Esempio n. 1
0
        public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
        {
            var startLoc = output.Location;

            output.Write("fixed", TextTokenKind.Keyword);
            output.WriteSpace();
            output.Write("(", TextTokenKind.Operator);
            for (int i = 0; i < this.Initializers.Count; i++)
            {
                if (i > 0)
                {
                    output.Write(",", TextTokenKind.Operator);
                    output.WriteSpace();
                }
                this.Initializers[i].WriteTo(output, null);
            }
            output.Write(")", TextTokenKind.Operator);
            var ilRanges = new List <ILRange>(ILRanges);

            foreach (var i in Initializers)
            {
                ilRanges.AddRange(i.GetSelfAndChildrenRecursiveILRanges());
            }
            UpdateMemberMapping(memberMapping, startLoc, output.Location, ilRanges);
            output.WriteSpace();
            this.BodyBlock.WriteTo(output, memberMapping);
        }
Esempio n. 2
0
        public static void WriteTo(this MethodSig sig, ITextOutput writer)
        {
            if (sig.ExplicitThis)
            {
                writer.Write("instance", TextTokenType.Keyword);
                writer.WriteSpace();
                writer.Write("explicit", TextTokenType.Keyword);
                writer.WriteSpace();
            }
            else if (sig.HasThis)
            {
                writer.Write("instance", TextTokenType.Keyword);
                writer.WriteSpace();
            }
            sig.RetType.WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
            writer.WriteSpace();
            writer.Write('(', TextTokenType.Operator);
            var parameters = sig.GetParameters();

            for (int i = 0; i < parameters.Count; ++i)
            {
                if (i > 0)
                {
                    writer.Write(',', TextTokenType.Operator);
                    writer.WriteSpace();
                }
                parameters[i].WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
            }
            writer.Write(")", TextTokenType.Operator);
        }
Esempio n. 3
0
 public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
 {
     output.Write(".try", TextTokenKind.Keyword);
     output.WriteSpace();
     TryBlock.WriteTo(output, memberMapping, ILRanges);
     foreach (CatchBlock block in CatchBlocks)
     {
         block.WriteTo(output, memberMapping);
     }
     if (FaultBlock != null)
     {
         output.Write("fault", TextTokenKind.Keyword);
         output.WriteSpace();
         FaultBlock.WriteTo(output, memberMapping);
     }
     if (FinallyBlock != null)
     {
         output.Write("finally", TextTokenKind.Keyword);
         output.WriteSpace();
         FinallyBlock.WriteTo(output, memberMapping);
     }
     if (FilterBlock != null)
     {
         output.Write("filter", TextTokenKind.Keyword);
         output.WriteSpace();
         FilterBlock.WriteTo(output, memberMapping);
     }
 }
Esempio n. 4
0
            public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
            {
                var startLoc = output.Location;

                if (IsFilter)
                {
                    output.Write("filter", TextTokenKind.Keyword);
                    output.WriteSpace();
                    output.WriteReference(ExceptionVariable.Name, ExceptionVariable, TextTokenKind.Local);
                }
                else if (ExceptionType != null)
                {
                    output.Write("catch", TextTokenKind.Keyword);
                    output.WriteSpace();
                    output.WriteReference(ExceptionType.FullName, ExceptionType, TextTokenKindUtils.GetTextTokenType(ExceptionType));
                    if (ExceptionVariable != null)
                    {
                        output.WriteSpace();
                        output.WriteReference(ExceptionVariable.Name, ExceptionVariable, TextTokenKind.Local);
                    }
                }
                else
                {
                    output.Write("handler", TextTokenKind.Keyword);
                    output.WriteSpace();
                    output.WriteReference(ExceptionVariable.Name, ExceptionVariable, TextTokenKind.Local);
                }
                UpdateMemberMapping(memberMapping, startLoc, output.Location, StlocILRanges);
                output.WriteSpace();
                base.WriteTo(output, memberMapping);
            }
Esempio n. 5
0
 public static ITextOutput Write(ITextOutput output, MethodDef method, Language language)
 {
     output.Write(CleanUpIdentifier(method.Name), TextTokenHelper.GetTextTokenType(method));
     output.Write('(', TextTokenType.Operator);
     for (int i = 0; i < method.Parameters.Count; i++)
     {
         if (method.Parameters[i].IsHiddenThisParameter)
         {
             continue;
         }
         if (method.Parameters[i].MethodSigIndex > 0)
         {
             output.Write(',', TextTokenType.Operator);
             output.WriteSpace();
         }
         language.TypeToString(output, method.Parameters[i].Type.ToTypeDefOrRef(), false, method.Parameters[i].ParamDef);
     }
     if (method.CallingConvention == CallingConvention.VarArg || method.CallingConvention == CallingConvention.NativeVarArg)
     {
         if (method.MethodSig.GetParamCount() > 0)
         {
             output.Write(',', TextTokenType.Operator);
             output.WriteSpace();
         }
         output.Write("...", TextTokenType.Operator);
     }
     output.Write(')', TextTokenType.Operator);
     output.WriteSpace();
     output.Write(':', TextTokenType.Operator);
     output.WriteSpace();
     language.TypeToString(output, method.ReturnType.ToTypeDefOrRef(), false, method.Parameters.ReturnParameter.ParamDef);
     method.MDToken.WriteSuffixString(output);
     return(output);
 }
Esempio n. 6
0
		public static ITextOutput Write(ITextOutput output, MethodDef method, Language language) {
			output.Write(UIUtils.CleanUpIdentifier(method.Name), TextTokenHelper.GetTextTokenType(method));
			output.Write('(', TextTokenType.Operator);
			for (int i = 0; i < method.Parameters.Count; i++) {
				if (method.Parameters[i].IsHiddenThisParameter)
					continue;
				if (method.Parameters[i].MethodSigIndex > 0) {
					output.Write(',', TextTokenType.Operator);
					output.WriteSpace();
				}
				language.TypeToString(output, method.Parameters[i].Type.ToTypeDefOrRef(), false, method.Parameters[i].ParamDef);
			}
			if (method.CallingConvention == CallingConvention.VarArg || method.CallingConvention == CallingConvention.NativeVarArg) {
				if (method.MethodSig.GetParamCount() > 0) {
					output.Write(',', TextTokenType.Operator);
					output.WriteSpace();
				}
				output.Write("...", TextTokenType.Operator);
			}
			output.Write(')', TextTokenType.Operator);
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, method.ReturnType.ToTypeDefOrRef(), false, method.Parameters.ReturnParameter.ParamDef);
			method.MDToken.WriteSuffixString(output);
			return output;
		}
Esempio n. 7
0
 public static void WriteTo(this Instruction instruction, ITextOutput writer, Func <OpCode, string> getOpCodeDocumentation)
 {
     writer.WriteDefinition(DnlibExtensions.OffsetToString(instruction.GetOffset()), instruction, TextTokenType.Label, false);
     writer.Write(':', TextTokenType.Operator);
     writer.WriteSpace();
     writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, TextTokenType.OpCode);
     if (instruction.Operand != null)
     {
         writer.WriteSpace();
         if (instruction.OpCode == OpCodes.Ldtoken)
         {
             var member = instruction.Operand as IMemberRef;
             if (member != null && member.IsMethod)
             {
                 writer.Write("method", TextTokenType.Keyword);
                 writer.WriteSpace();
             }
             else if (member != null && member.IsField)
             {
                 writer.Write("field", TextTokenType.Keyword);
                 writer.WriteSpace();
             }
         }
         WriteOperand(writer, instruction.Operand);
     }
     if (getOpCodeDocumentation != null)
     {
         var doc = getOpCodeDocumentation(instruction.OpCode);
         if (doc != null)
         {
             writer.Write("\t", TextTokenType.Text);
             writer.Write("// " + doc, TextTokenType.Comment);
         }
     }
 }
Esempio n. 8
0
		public override void DecompileMethod(MethodDef method, ITextOutput output, DecompilationOptions options)
		{
			WriteComment(output, "Method: ");
			output.WriteDefinition(IdentifierEscaper.Escape(method.FullName), method, TextTokenType.Comment, false);
			output.WriteLine();

			if (!method.HasBody) {
				return;
			}
			
			StartKeywordBlock(output, ".body", method);

			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
			ilMethod.Body = astBuilder.Build(method, inlineVariables, context);
			
			if (abortBeforeStep != null) {
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			if (context.CurrentMethodIsAsync) {
				output.Write("async", TextTokenType.Keyword);
				output.Write('/', TextTokenType.Operator);
				output.WriteLine("await", TextTokenType.Keyword);
			}
			
			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(IdentifierEscaper.Escape(v.Name), v, v.IsParameter ? TextTokenType.Parameter : TextTokenType.Local);
				if (v.Type != null) {
					output.WriteSpace();
					output.Write(':', TextTokenType.Operator);
					output.WriteSpace();
					if (v.IsPinned) {
						output.Write("pinned", TextTokenType.Keyword);
						output.WriteSpace();
					}
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				if (v.IsGenerated) {
					output.WriteSpace();
					output.Write('[', TextTokenType.Operator);
					output.Write("generated", TextTokenType.Keyword);
					output.Write(']', TextTokenType.Operator);
				}
				output.WriteLine();
			}
			
			var memberMapping = new MemberMapping(method);
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output, memberMapping);
				if (!node.WritesNewLine)
					output.WriteLine();
			}
			output.AddDebugSymbols(memberMapping);
			EndKeywordBlock(output);
		}
Esempio n. 9
0
 static void WriteLong(this ITextOutput output, InstructionVM instr)
 {
     output.WriteShort(instr);
     output.WriteSpace();
     output.Write(instr.Code.ToOpCode().Name, TextTokenType.OpCode);
     output.WriteSpace();
     Write(output, instr.InstructionOperandVM);
 }
Esempio n. 10
0
 public virtual void WriteToolTip(ITextOutput output, IVariable variable, string name)
 {
     output.Write(variable is Local ? "(local variable)" : "(parameter)", TextTokenType.Text);
     output.WriteSpace();
     WriteToolTip(output, variable.Type.ToTypeDefOrRef(), variable is Parameter ? ((Parameter)variable).ParamDef : null);
     output.WriteSpace();
     output.Write(IdentifierEscaper.Escape(GetName(variable, name)), variable is Local ? TextTokenType.Local : TextTokenType.Parameter);
 }
Esempio n. 11
0
		public static ITextOutput Write(ITextOutput output, PropertyDef property, Language language, bool? isIndexer = null) {
			language.FormatPropertyName(output, property, isIndexer);
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, property.PropertySig.GetRetType().ToTypeDefOrRef(), false, property);
			property.MDToken.WriteSuffixString(output);
			return output;
		}
Esempio n. 12
0
		protected override void Write(ITextOutput output) {
			output.Write(string.Format("{0}", index + 1), TextTokenType.Number);
			if (infoTuple != null) {
				output.WriteSpace();
				output.Write('-', TextTokenType.Operator);
				output.WriteSpace();
				infoTuple.Item2(output);
			}
		}
Esempio n. 13
0
		public static ITextOutput Write(ITextOutput output, EventDef ev, Language language) {
			output.Write(UIUtils.CleanUpIdentifier(ev.Name), TextTokenHelper.GetTextTokenType(ev));
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, ev.EventType, false, ev);
			ev.MDToken.WriteSuffixString(output);
			return output;
		}
Esempio n. 14
0
		public static ITextOutput Write(ITextOutput output, FieldDef field, Language language) {
			output.Write(UIUtils.CleanUpIdentifier(field.Name), TextTokenHelper.GetTextTokenType(field));
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, field.FieldType.ToTypeDefOrRef(), false, field);
			field.MDToken.WriteSuffixString(output);
			return output;
		}
Esempio n. 15
0
		protected override void Write(ITextOutput output) {
			output.Write(string.Format("{0:X2}", (byte)tablesStreamVM.Table), TextTokenType.Number);
			output.WriteSpace();
			output.Write(string.Format("{0}", tablesStreamVM.Table), TextTokenType.Type);
			output.WriteSpace();
			output.Write('(', TextTokenType.Operator);
			output.Write(string.Format("{0}", tablesStreamVM.Rows), TextTokenType.Number);
			output.Write(')', TextTokenType.Operator);
		}
		protected override void Write(ITextOutput output) {
			output.Write("Section", TextTokenType.Keyword);
			output.WriteSpace();
			output.Write('#', TextTokenType.Operator);
			output.Write(sectionNumber.ToString(), TextTokenType.Number);
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			output.Write(string.Format("{0}", imageSectionHeaderVM.NameVM.String), TextTokenType.Type);
		}
Esempio n. 17
0
 void StartKeywordBlock(ITextOutput output, string keyword, IMemberDef member)
 {
     output.Write(keyword, TextTokenKind.Keyword);
     output.WriteSpace();
     output.WriteDefinition(IdentifierEscaper.Escape(member.Name), member, TextTokenKindUtils.GetTextTokenType(member), false);
     output.WriteSpace();
     output.WriteLeftBrace();
     output.WriteLine();
     output.Indent();
 }
Esempio n. 18
0
 public static ITextOutput Write(ITextOutput output, EventDef ev, Language language)
 {
     output.Write(UIUtils.CleanUpIdentifier(ev.Name), TextTokenHelper.GetTextTokenType(ev));
     output.WriteSpace();
     output.Write(':', TextTokenType.Operator);
     output.WriteSpace();
     language.TypeToString(output, ev.EventType, false, ev);
     ev.MDToken.WriteSuffixString(output);
     return(output);
 }
Esempio n. 19
0
 protected override void Write(ITextOutput output)
 {
     output.Write(string.Format("{0:X2}", (byte)tablesStreamVM.Table), TextTokenType.Number);
     output.WriteSpace();
     output.Write(string.Format("{0}", tablesStreamVM.Table), TextTokenType.Type);
     output.WriteSpace();
     output.Write('(', TextTokenType.Operator);
     output.Write(string.Format("{0}", tablesStreamVM.Rows), TextTokenType.Number);
     output.Write(')', TextTokenType.Operator);
 }
Esempio n. 20
0
 protected override void Write(ITextOutput output)
 {
     output.Write("Section", TextTokenType.Keyword);
     output.WriteSpace();
     output.Write('#', TextTokenType.Operator);
     output.Write(sectionNumber.ToString(), TextTokenType.Number);
     output.Write(':', TextTokenType.Operator);
     output.WriteSpace();
     output.Write(string.Format("{0}", imageSectionHeaderVM.NameVM.String), TextTokenType.Type);
 }
Esempio n. 21
0
 public static ITextOutput Write(ITextOutput output, FieldDef field, Language language)
 {
     output.Write(UIUtils.CleanUpIdentifier(field.Name), TextTokenHelper.GetTextTokenType(field));
     output.WriteSpace();
     output.Write(':', TextTokenType.Operator);
     output.WriteSpace();
     language.TypeToString(output, field.FieldType.ToTypeDefOrRef(), false, field);
     field.MDToken.WriteSuffixString(output);
     return(output);
 }
Esempio n. 22
0
 protected override void Write(ITextOutput output)
 {
     output.Write(string.Format("{0}", index + 1), TextTokenType.Number);
     if (infoTuple != null)
     {
         output.WriteSpace();
         output.Write('-', TextTokenType.Operator);
         output.WriteSpace();
         infoTuple.Item2(output);
     }
 }
Esempio n. 23
0
        public void WriteName(BreakpointVM vm)
        {
            var ilbp = vm.Breakpoint as ILCodeBreakpoint;

            if (ilbp != null)
            {
                vm.NameError = false;
                bool printedToken = false;
                if (BreakpointSettings.Instance.ShowTokens)
                {
                    WriteToken(output, ilbp.SerializedDnSpyToken.Token);
                    output.WriteSpace();
                    printedToken = true;
                }
                // If this is a method in a dynamic module and the module hasn't been loaded yet,
                // this call will try to load it, and then open a dialog box showing the progress.
                // But in rare cases we can't show the dialog box because of Dispatcher limitations,
                // so if we must load the module, fail. Passing in false will prevent loading
                // dynamic modules.
                var method = vm.GetMethodDef(false);
                if (method == null)
                {
                    vm.NameError = true;
                    if (printedToken)
                    {
                        output.Write("???", TextTokenType.Error);
                    }
                    else
                    {
                        output.Write(string.Format("0x{0:X8}", ilbp.SerializedDnSpyToken.Token), TextTokenType.Number);
                    }
                }
                else
                {
                    MethodLanguage.WriteToolTip(output, method, null);
                }
                output.WriteSpace();
                output.Write('+', TextTokenType.Operator);
                output.WriteSpace();
                WriteILOffset(output, ilbp.ILOffset);
                return;
            }

            var debp = vm.Breakpoint as DebugEventBreakpoint;

            if (debp != null)
            {
                //TODO:
                return;
            }

            Debug.Fail(string.Format("Unknown breakpoint type: {0}", vm.Breakpoint.GetType()));
        }
Esempio n. 24
0
 protected override void Write(ITextOutput output)
 {
     output.Write("Storage", TextTokenType.InstanceField);
     output.WriteSpace();
     output.Write("Stream", TextTokenType.InstanceField);
     output.WriteSpace();
     output.Write('#', TextTokenType.Operator);
     output.Write(streamNumber.ToString(), TextTokenType.Number);
     output.Write(':', TextTokenType.Operator);
     output.WriteSpace();
     output.Write(string.Format("{0}", storageStreamVM.RCNameVM.StringZ), storageStreamType == StorageStreamType.None ? TextTokenType.Error : TextTokenType.Type);
 }
Esempio n. 25
0
		public static void WriteTo(this Instruction instruction, ITextOutput writer, Func<OpCode, string> getOpCodeDocumentation)
		{
			writer.WriteDefinition(DnlibExtensions.OffsetToString(instruction.GetOffset()), instruction, TextTokenType.Label, false);
			writer.Write(':', TextTokenType.Operator);
			writer.WriteSpace();
			writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, TextTokenType.OpCode);
			if (instruction.Operand != null) {
				writer.WriteSpace();
				if (instruction.OpCode == OpCodes.Ldtoken) {
					var member = instruction.Operand as IMemberRef;
					if (member != null && member.IsMethod) {
						writer.Write("method", TextTokenType.Keyword);
						writer.WriteSpace();
					}
					else if (member != null && member.IsField) {
						writer.Write("field", TextTokenType.Keyword);
						writer.WriteSpace();
					}
				}
				WriteOperand(writer, instruction.Operand);
			}
			if (getOpCodeDocumentation != null) {
				var doc = getOpCodeDocumentation(instruction.OpCode);
				if (doc != null) {
					writer.Write("\t", TextTokenType.Text);
					writer.Write("// " + doc, TextTokenType.Comment);
				}
			}
		}
Esempio n. 26
0
 static void WriteShort(this ITextOutput output, InstructionVM instr)
 {
     output.Write(instr.Index.ToString(), TextTokenType.Number);
     output.WriteSpace();
     output.Write('(', TextTokenType.Operator);
     output.Write(string.Format("{0:X4}", instr.Offset), TextTokenType.Number);
     output.Write(')', TextTokenType.Operator);
 }
Esempio n. 27
0
 public static void WriteTo(this ExceptionHandler exceptionHandler, ITextOutput writer, MethodDef method)
 {
     writer.Write("Try", TextTokenType.Keyword);
     writer.WriteSpace();
     WriteOffsetReference(writer, exceptionHandler.TryStart, method);
     writer.Write('-', TextTokenType.Operator);
     WriteOffsetReference(writer, exceptionHandler.TryEnd, method);
     writer.WriteSpace();
     writer.Write(exceptionHandler.HandlerType.ToString(), TextTokenType.Keyword);
     if (exceptionHandler.FilterStart != null)
     {
         writer.WriteSpace();
         WriteOffsetReference(writer, exceptionHandler.FilterStart, method);
         writer.WriteSpace();
         writer.Write("handler", TextTokenType.Keyword);
         writer.WriteSpace();
     }
     if (exceptionHandler.CatchType != null)
     {
         writer.WriteSpace();
         exceptionHandler.CatchType.WriteTo(writer);
     }
     writer.WriteSpace();
     WriteOffsetReference(writer, exceptionHandler.HandlerStart, method);
     writer.Write('-', TextTokenType.Operator);
     WriteOffsetReference(writer, exceptionHandler.HandlerEnd, method);
 }
Esempio n. 28
0
		public static void WriteTo(this ExceptionHandler exceptionHandler, ITextOutput writer, MethodDef method)
		{
			writer.Write("Try", TextTokenType.Keyword);
			writer.WriteSpace();
			WriteOffsetReference(writer, exceptionHandler.TryStart, method);
			writer.Write('-', TextTokenType.Operator);
			WriteOffsetReference(writer, exceptionHandler.TryEnd, method);
			writer.WriteSpace();
			writer.Write(exceptionHandler.HandlerType.ToString(), TextTokenType.Keyword);
			if (exceptionHandler.FilterStart != null) {
				writer.WriteSpace();
				WriteOffsetReference(writer, exceptionHandler.FilterStart, method);
				writer.WriteSpace();
				writer.Write("handler", TextTokenType.Keyword);
				writer.WriteSpace();
			}
			if (exceptionHandler.CatchType != null) {
				writer.WriteSpace();
				exceptionHandler.CatchType.WriteTo(writer);
			}
			writer.WriteSpace();
			WriteOffsetReference(writer, exceptionHandler.HandlerStart, method);
			writer.Write('-', TextTokenType.Operator);
			WriteOffsetReference(writer, exceptionHandler.HandlerEnd, method);
		}
Esempio n. 29
0
 bool WriteRefIfByRef(ITextOutput output, TypeSig typeSig, ParamDef pd)
 {
     if (typeSig.RemovePinnedAndModifiers() is ByRefSig)
     {
         if (pd != null && (!pd.IsIn && pd.IsOut))
         {
             output.Write("out", TextTokenKind.Keyword);
             output.WriteSpace();
         }
         else
         {
             output.Write("ref", TextTokenKind.Keyword);
             output.WriteSpace();
         }
         return(true);
     }
     return(false);
 }
Esempio n. 30
0
        public static void WriteSuffixString(this MDToken token, ITextOutput output)
        {
            if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens)
            {
                return;
            }

            output.WriteSpace();
            output.Write('@', TextTokenType.Operator);
            output.Write(string.Format("{0:X8}", token.ToUInt32()), TextTokenType.Number);
        }
Esempio n. 31
0
		protected override void Write(ITextOutput output, Language language) {
			if (hidesParent) {
				output.Write('(', TextTokenType.Operator);
				output.Write("hides", TextTokenType.Text);
				output.Write(')', TextTokenType.Operator);
				output.WriteSpace();
			}
			Language.TypeToString(output, analyzedEvent.DeclaringType, true);
			output.Write('.', TextTokenType.Operator);
			EventTreeNode.Write(output, analyzedEvent, Language);
		}
Esempio n. 32
0
 public static void WriteFieldTo(this IField field, ITextOutput writer)
 {
     if (field == null || field.FieldSig == null)
     {
         return;
     }
     field.FieldSig.Type.WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
     writer.WriteSpace();
     field.DeclaringType.WriteTo(writer, ILNameSyntax.TypeName);
     writer.Write("::", TextTokenType.Operator);
     writer.WriteReference(Escape(field.Name), field, TextTokenHelper.GetTextTokenType(field));
 }
Esempio n. 33
0
        public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
        {
            var startLoc = output.Location;

            output.Write("switch", TextTokenKind.Keyword);
            output.WriteSpace();
            output.Write("(", TextTokenKind.Operator);
            Condition.WriteTo(output, null);
            output.Write(")", TextTokenKind.Operator);
            var ilRanges = new List <ILRange>(ILRanges);

            ilRanges.AddRange(Condition.GetSelfAndChildrenRecursiveILRanges());
            UpdateMemberMapping(memberMapping, startLoc, output.Location, ilRanges);
            output.WriteSpace();
            WriteHiddenStart(output, memberMapping);
            foreach (CaseBlock caseBlock in this.CaseBlocks)
            {
                caseBlock.WriteTo(output, memberMapping);
            }
            WriteHiddenEnd(output, memberMapping);
        }
Esempio n. 34
0
 /// <summary>
 /// Converts a member signature to a string.
 /// This is used for displaying the tooltip on a member reference.
 /// </summary>
 public virtual void WriteToolTip(ITextOutput output, IMemberRef member, IHasCustomAttribute typeAttributes)
 {
     if (member is ITypeDefOrRef)
     {
         TypeToString(output, (ITypeDefOrRef)member, true, typeAttributes);
     }
     else if (member is GenericParam)
     {
         var gp = (GenericParam)member;
         output.Write(IdentifierEscaper.Escape(gp.Name), TextTokenHelper.GetTextTokenType(gp));
         output.WriteSpace();
         output.Write("in", TextTokenType.Text);
         output.WriteSpace();
         WriteToolTip(output, gp.Owner, typeAttributes);
     }
     else
     {
         //TODO: This should be escaped but since it contains whitespace, parens, etc,
         //		we can't pass it to IdentifierEscaper.Escape().
         output.Write(member.ToString(), TextTokenHelper.GetTextTokenType(member));
     }
 }
Esempio n. 35
0
        public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
        {
            var startLoc = output.Location;

            output.Write("if", TextTokenKind.Keyword);
            output.WriteSpace();
            output.Write("(", TextTokenKind.Operator);
            Condition.WriteTo(output, null);
            output.Write(")", TextTokenKind.Operator);
            var ilRanges = new List <ILRange>(ILRanges);

            ilRanges.AddRange(Condition.GetSelfAndChildrenRecursiveILRanges());
            UpdateMemberMapping(memberMapping, startLoc, output.Location, ilRanges);
            output.WriteSpace();
            TrueBlock.WriteTo(output, memberMapping);
            if (FalseBlock != null)
            {
                output.Write("else", TextTokenKind.Keyword);
                output.WriteSpace();
                FalseBlock.WriteTo(output, memberMapping);
            }
        }
Esempio n. 36
0
        public override void WriteTo(ITextOutput output, MemberMapping memberMapping)
        {
            var startLoc = output.Location;

            output.Write("loop", TextTokenKind.Keyword);
            output.WriteSpace();
            output.Write("(", TextTokenKind.Operator);
            if (this.Condition != null)
            {
                this.Condition.WriteTo(output, null);
            }
            output.Write(")", TextTokenKind.Operator);
            var ilRanges = new List <ILRange>(ILRanges);

            if (this.Condition != null)
            {
                ilRanges.AddRange(this.Condition.GetSelfAndChildrenRecursiveILRanges());
            }
            UpdateMemberMapping(memberMapping, startLoc, output.Location, ilRanges);
            output.WriteSpace();
            this.BodyBlock.WriteTo(output, memberMapping);
        }
Esempio n. 37
0
 protected override void Write(ITextOutput output, Language language)
 {
     if (hidesParent)
     {
         output.Write('(', TextTokenType.Operator);
         output.Write("hides", TextTokenType.Text);
         output.Write(')', TextTokenType.Operator);
         output.WriteSpace();
     }
     Language.TypeToString(output, analyzedEvent.DeclaringType, true);
     output.Write('.', TextTokenType.Operator);
     EventTreeNode.Write(output, analyzedEvent, Language);
 }
Esempio n. 38
0
        public void WriteName(BreakpointVM vm)
        {
            var ilbp = vm.Breakpoint as ILCodeBreakpoint;

            if (ilbp != null)
            {
                var module = GetModule(ilbp) as ModuleDefMD;
                if (BreakpointSettings.Instance.ShowTokens)
                {
                    WriteToken(output, ilbp.MethodKey.Token);
                    output.WriteSpace();
                }
                var method = module == null ? null : module.ResolveToken(ilbp.MethodKey.Token) as IMemberRef;
                if (method == null)
                {
                    output.Write(string.Format("0x{0:X8}", ilbp.MethodKey.Token), TextTokenType.Number);
                }
                else
                {
                    MethodLanguage.WriteToolTip(output, method, null);
                }
                output.WriteSpace();
                output.Write('+', TextTokenType.Operator);
                output.WriteSpace();
                WriteILOffset(output, ilbp.ILOffset);
                return;
            }

            var debp = vm.Breakpoint as DebugEventBreakpoint;

            if (debp != null)
            {
                //TODO:
                return;
            }

            Debug.Fail(string.Format("Unknown breakpoint type: {0}", vm.Breakpoint.GetType()));
        }
Esempio n. 39
0
 static void Write(this ITextOutput output, IList <InstructionVM> instrs)
 {
     output.Write('[', TextTokenType.Operator);
     for (int i = 0; i < instrs.Count; i++)
     {
         if (i > 0)
         {
             output.Write(',', TextTokenType.Operator);
             output.WriteSpace();
         }
         output.WriteShort(instrs[i]);
     }
     output.Write(']', TextTokenType.Operator);
 }
Esempio n. 40
0
 static void WriteLabelList(ITextOutput writer, IList <Instruction> instructions, MethodDef method)
 {
     writer.Write("(", TextTokenType.Operator);
     for (int i = 0; i < instructions.Count; i++)
     {
         if (i != 0)
         {
             writer.Write(',', TextTokenType.Operator);
             writer.WriteSpace();
         }
         WriteOffsetReference(writer, instructions[i], method);
     }
     writer.Write(")", TextTokenType.Operator);
 }
Esempio n. 41
0
 static void WriteLabelList(ITextOutput writer, IList<Instruction> instructions, MethodDef method)
 {
     writer.Write("(", TextTokenType.Operator);
     for(int i = 0; i < instructions.Count; i++) {
         if (i != 0) {
             writer.Write(',', TextTokenType.Operator);
             writer.WriteSpace();
         }
         WriteOffsetReference(writer, instructions[i], method);
     }
     writer.Write(")", TextTokenType.Operator);
 }
Esempio n. 42
0
 internal static void WriteKeyword(ITextOutput writer, string name, ITypeDefOrRef tdr)
 {
     var parts = name.Split(' ');
     for (int i = 0; i < parts.Length; i++) {
         if (i > 0)
             writer.WriteSpace();
         if (tdr != null)
             writer.WriteReference(parts[i], tdr, TextTokenType.Keyword);
         else
             writer.Write(parts[i], TextTokenType.Keyword);
     }
 }
Esempio n. 43
0
        public static void WriteTo(this ITypeDefOrRef type, ITextOutput writer, ILNameSyntax syntax, int depth)
        {
            if (depth++ > MAX_CONVERTTYPE_DEPTH || type == null)
                return;
            var ts = type as TypeSpec;
            if (ts != null && !(ts.TypeSig is FnPtrSig)) {
                WriteTo(((TypeSpec)type).TypeSig, writer, syntax, depth);
                return;
            }
            string typeFullName = type.FullName;
            string typeName = type.Name.String;
            if (ts != null) {
                var fnPtrSig = ts.TypeSig as FnPtrSig;
                typeFullName = DnlibExtensions.GetFnPtrFullName(fnPtrSig);
                typeName = DnlibExtensions.GetFnPtrName(fnPtrSig);
            }
            TypeSig typeSig = null;
            string name = type.DefinitionAssembly.IsCorLib() ? PrimitiveTypeName(typeFullName, type.Module, out typeSig) : null;
            if (syntax == ILNameSyntax.ShortTypeName) {
                if (name != null)
                    WriteKeyword(writer, name, typeSig.ToTypeDefOrRef());
                else
                    writer.WriteReference(Escape(typeName), type, TextTokenHelper.GetTextTokenType(type));
            } else if ((syntax == ILNameSyntax.Signature || syntax == ILNameSyntax.SignatureNoNamedTypeParameters) && name != null) {
                WriteKeyword(writer, name, typeSig.ToTypeDefOrRef());
            } else {
                if (syntax == ILNameSyntax.Signature || syntax == ILNameSyntax.SignatureNoNamedTypeParameters) {
                    writer.Write(DnlibExtensions.IsValueType(type) ? "valuetype" : "class", TextTokenType.Keyword);
                    writer.WriteSpace();
                }

                if (type.DeclaringType != null) {
                    type.DeclaringType.WriteTo(writer, ILNameSyntax.TypeName, depth);
                    writer.Write('/', TextTokenType.Operator);
                    writer.WriteReference(Escape(typeName), type, TextTokenHelper.GetTextTokenType(type));
                } else {
                    if (!(type is TypeDef) && type.Scope != null && !(type is TypeSpec)) {
                        writer.Write('[', TextTokenType.Operator);
                        writer.Write(Escape(type.Scope.GetScopeName()), TextTokenType.ILModule);
                        writer.Write(']', TextTokenType.Operator);
                    }
                    if (ts != null || MustEscape(typeFullName))
                        writer.WriteReference(Escape(typeFullName), type, TextTokenHelper.GetTextTokenType(type));
                    else {
                        WriteNamespace(writer, type.Namespace);
                        if (!string.IsNullOrEmpty(type.Namespace))
                            writer.Write('.', TextTokenType.Operator);
                        writer.WriteReference(IdentifierEscaper.Escape(type.Name), type, TextTokenHelper.GetTextTokenType(type));
                    }
                }
            }
        }
Esempio n. 44
0
 public static void WriteTo(this TypeSig type, ITextOutput writer, ILNameSyntax syntax, int depth)
 {
     if (depth++ > MAX_CONVERTTYPE_DEPTH)
         return;
     ILNameSyntax syntaxForElementTypes = syntax == ILNameSyntax.SignatureNoNamedTypeParameters ? syntax : ILNameSyntax.Signature;
     if (type is PinnedSig) {
         ((PinnedSig)type).Next.WriteTo(writer, syntaxForElementTypes, depth);
         writer.WriteSpace();
         writer.Write("pinned", TextTokenType.Keyword);
     } else if (type is ArraySig) {
         ArraySig at = (ArraySig)type;
         at.Next.WriteTo(writer, syntaxForElementTypes, depth);
         writer.Write('[', TextTokenType.Operator);
         for (int i = 0; i < at.Rank; i++)
         {
             if (i != 0) {
                 writer.Write(',', TextTokenType.Operator);
                 writer.WriteSpace();
             }
             int? lower = i < at.LowerBounds.Count ? at.LowerBounds[i] : (int?)null;
             uint? size = i < at.Sizes.Count ? at.Sizes[i] : (uint?)null;
             if (lower != null)
             {
                 writer.Write(lower.ToString(), TextTokenType.Number);
                 if (size != null) {
                     writer.Write("..", TextTokenType.Operator);
                     writer.Write((lower.Value + (int)size.Value - 1).ToString(), TextTokenType.Number);
                 }
                 else
                     writer.Write("...", TextTokenType.Operator);
             }
         }
         writer.Write(']', TextTokenType.Operator);
     } else if (type is SZArraySig) {
         SZArraySig at = (SZArraySig)type;
         at.Next.WriteTo(writer, syntaxForElementTypes, depth);
         writer.Write("[]", TextTokenType.Operator);
     } else if (type is GenericSig) {
         if (((GenericSig)type).IsMethodVar)
             writer.Write("!!", TextTokenType.Operator);
         else
             writer.Write("!", TextTokenType.Operator);
         string typeName = type.TypeName;
         if (string.IsNullOrEmpty(typeName) || typeName[0] == '!' || syntax == ILNameSyntax.SignatureNoNamedTypeParameters)
             writer.Write(((GenericSig)type).Number.ToString(), TextTokenType.Number);
         else
             writer.Write(Escape(typeName), TextTokenHelper.GetTextTokenType(type));
     } else if (type is ByRefSig) {
         ((ByRefSig)type).Next.WriteTo(writer, syntaxForElementTypes, depth);
         writer.Write('&', TextTokenType.Operator);
     } else if (type is PtrSig) {
         ((PtrSig)type).Next.WriteTo(writer, syntaxForElementTypes, depth);
         writer.Write('*', TextTokenType.Operator);
     } else if (type is GenericInstSig) {
         ((GenericInstSig)type).GenericType.WriteTo(writer, syntaxForElementTypes, depth);
         writer.Write('<', TextTokenType.Operator);
         var arguments = ((GenericInstSig)type).GenericArguments;
         for (int i = 0; i < arguments.Count; i++) {
             if (i > 0) {
                 writer.Write(',', TextTokenType.Operator);
                 writer.WriteSpace();
             }
             arguments[i].WriteTo(writer, syntaxForElementTypes, depth);
         }
         writer.Write('>', TextTokenType.Operator);
     } else if (type is CModOptSig) {
         ((ModifierSig)type).Next.WriteTo(writer, syntax, depth);
         writer.WriteSpace();
         writer.Write("modopt", TextTokenType.Keyword);
         writer.Write('(', TextTokenType.Operator);
         ((ModifierSig)type).Modifier.WriteTo(writer, ILNameSyntax.TypeName, depth);
         writer.Write(')', TextTokenType.Operator);
         writer.WriteSpace();
     }
     else if (type is CModReqdSig) {
         ((ModifierSig)type).Next.WriteTo(writer, syntax, depth);
         writer.WriteSpace();
         writer.Write("modreq", TextTokenType.Keyword);
         writer.Write('(', TextTokenType.Operator);
         ((ModifierSig)type).Modifier.WriteTo(writer, ILNameSyntax.TypeName, depth);
         writer.Write(')', TextTokenType.Operator);
         writer.WriteSpace();
     }
     else if (type is TypeDefOrRefSig) {
         WriteTo(((TypeDefOrRefSig)type).TypeDefOrRef, writer, syntax, depth);
     } else if (type is FnPtrSig) {
         WriteTo(type.ToTypeDefOrRef(), writer, syntax, depth);
     }
     //TODO: SentinelSig
 }
Esempio n. 45
0
 public static void WriteTo(this MethodSig sig, ITextOutput writer)
 {
     if (sig.ExplicitThis) {
         writer.Write("instance", TextTokenType.Keyword);
         writer.WriteSpace();
         writer.Write("explicit", TextTokenType.Keyword);
         writer.WriteSpace();
     }
     else if (sig.HasThis) {
         writer.Write("instance", TextTokenType.Keyword);
         writer.WriteSpace();
     }
     sig.RetType.WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
     writer.WriteSpace();
     writer.Write('(', TextTokenType.Operator);
     var parameters = sig.GetParameters();
     for(int i = 0; i < parameters.Count; ++i) {
         if (i > 0) {
             writer.Write(',', TextTokenType.Operator);
             writer.WriteSpace();
         }
         parameters[i].WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
     }
     writer.Write(")", TextTokenType.Operator);
 }
Esempio n. 46
0
		/// <summary>
		/// Converts a member signature to a string.
		/// This is used for displaying the tooltip on a member reference.
		/// </summary>
		public virtual void WriteToolTip(ITextOutput output, IMemberRef member, IHasCustomAttribute typeAttributes)
		{
			if (member is ITypeDefOrRef)
				TypeToString(output, (ITypeDefOrRef)member, true, typeAttributes);
			else if (member is GenericParam) {
				var gp = (GenericParam)member;
				output.Write(IdentifierEscaper.Escape(gp.Name), TextTokenHelper.GetTextTokenType(gp));
				output.WriteSpace();
				output.Write("in", TextTokenType.Text);
				output.WriteSpace();
				WriteToolTip(output, gp.Owner, typeAttributes);
			}
			else {
				//TODO: This should be escaped but since it contains whitespace, parens, etc,
				//		we can't pass it to IdentifierEscaper.Escape().
				output.Write(member.ToString(), TextTokenHelper.GetTextTokenType(member));
			}
		}
Esempio n. 47
0
		public override void DecompileField(FieldDef field, ITextOutput output, DecompilationOptions options)
		{
			output.WriteReference(IdentifierEscaper.Escape(field.FieldType.GetFullName()), field.FieldType.ToTypeDefOrRef(), TextTokenHelper.GetTextTokenType(field.FieldType));
			output.WriteSpace();
			output.WriteDefinition(IdentifierEscaper.Escape(field.Name), field, TextTokenHelper.GetTextTokenType(field), false);
			var c = field.Constant;
			if (c != null) {
				output.WriteSpace();
				output.Write('=', TextTokenType.Operator);
				output.WriteSpace();
				if (c.Value == null)
					output.Write("null", TextTokenType.Keyword);
				else {
					switch (c.Type) {
					case ElementType.Boolean:
						if (c.Value is bool)
							output.Write((bool)c.Value ? "true" : "false", TextTokenType.Keyword);
						else
							goto default;
						break;

					case ElementType.Char:
						output.Write(string.Format("'{0}'", c.Value), TextTokenType.Char);
						break;

					case ElementType.I1:
					case ElementType.U1:
					case ElementType.I2:
					case ElementType.U2:
					case ElementType.I4:
					case ElementType.U4:
					case ElementType.I8:
					case ElementType.U8:
					case ElementType.R4:
					case ElementType.R8:
					case ElementType.I:
					case ElementType.U:
						output.Write(string.Format("{0}", c.Value), TextTokenType.Number);
						break;

					case ElementType.String:
						output.Write(string.Format("{0}", c.Value), TextTokenType.String);
						break;

					default:
						output.Write(string.Format("{0}", c.Value), TextTokenType.Text);
						break;
					}
				}
			}
		}
Esempio n. 48
0
 public static void WriteFieldTo(this IField field, ITextOutput writer)
 {
     if (field == null || field.FieldSig == null)
         return;
     field.FieldSig.Type.WriteTo(writer, ILNameSyntax.SignatureNoNamedTypeParameters);
     writer.WriteSpace();
     field.DeclaringType.WriteTo(writer, ILNameSyntax.TypeName);
     writer.Write("::", TextTokenType.Operator);
     writer.WriteReference(Escape(field.Name), field, TextTokenHelper.GetTextTokenType(field));
 }
Esempio n. 49
0
        static void Write(ITextOutput output, IAssembly asm)
        {
            var asmDef = asm as AssemblyDef;
            bool isExe = asmDef != null &&
                asmDef.ManifestModule != null &&
                (asmDef.ManifestModule.Characteristics & dnlib.PE.Characteristics.Dll) == 0;
            output.Write(asm.Name, isExe ? TextTokenType.AssemblyExe : TextTokenType.Assembly);

            output.Write(',', TextTokenType.Operator);
            output.WriteSpace();

            output.Write("Version", TextTokenType.InstanceProperty);
            output.Write('=', TextTokenType.Operator);
            output.Write(asm.Version.Major.ToString(), TextTokenType.Number);
            output.Write('.', TextTokenType.Operator);
            output.Write(asm.Version.Minor.ToString(), TextTokenType.Number);
            output.Write('.', TextTokenType.Operator);
            output.Write(asm.Version.Build.ToString(), TextTokenType.Number);
            output.Write('.', TextTokenType.Operator);
            output.Write(asm.Version.Revision.ToString(), TextTokenType.Number);

            output.Write(',', TextTokenType.Operator);
            output.WriteSpace();

            output.Write("Culture", TextTokenType.InstanceProperty);
            output.Write('=', TextTokenType.Operator);
            output.Write(UTF8String.IsNullOrEmpty(asm.Culture) ? "neutral" : asm.Culture.String, TextTokenType.EnumField);

            output.Write(',', TextTokenType.Operator);
            output.WriteSpace();

            var publicKey = PublicKeyBase.ToPublicKeyToken(asm.PublicKeyOrToken);
            output.Write(publicKey == null || publicKey is PublicKeyToken ? "PublicKeyToken" : "PublicKey", TextTokenType.InstanceProperty);
            output.Write('=', TextTokenType.Operator);
            if (PublicKeyBase.IsNullOrEmpty2(publicKey))
                output.Write("null", TextTokenType.Keyword);
            else
                output.Write(publicKey.ToString(), TextTokenType.Number);

            if ((asm.Attributes & AssemblyAttributes.Retargetable) != 0) {
                output.Write(',', TextTokenType.Operator);
                output.WriteSpace();
                output.Write("Retargetable", TextTokenType.InstanceProperty);
                output.Write('=', TextTokenType.Operator);
                output.Write("Yes", TextTokenType.EnumField);
            }

            if ((asm.Attributes & AssemblyAttributes.ContentType_Mask) == AssemblyAttributes.ContentType_WindowsRuntime) {
                output.Write(',', TextTokenType.Operator);
                output.WriteSpace();
                output.Write("ContentType", TextTokenType.InstanceProperty);
                output.Write('=', TextTokenType.Operator);
                output.Write("WindowsRuntime", TextTokenType.EnumField);
            }
        }
Esempio n. 50
0
 void WriteMethodName(ITextOutput output, IMethod method, string name)
 {
     string[] list;
     if (nameToOperatorName.TryGetValue(name, out list)) {
         for (int i = 0; i < list.Length; i++) {
             if (i > 0)
                 output.WriteSpace();
             var s = list[i];
             output.Write(s, 'a' <= s[0] && s[0] <= 'z' ? TextTokenType.Keyword : TextTokenType.Operator);
         }
     }
     else
         output.Write(IdentifierEscaper.Escape(name), TextTokenHelper.GetTextTokenType(method));
 }
Esempio n. 51
0
        protected override void Write(ITextOutput output, Language language)
        {
            if (!assembly.IsLoaded)
                output.Write(UIUtils.CleanUpName(assembly.ShortName), TextTokenType.Assembly);
            else if (assembly.ModuleDefinition == null)
                output.Write(UIUtils.CleanUpName(assembly.ShortName), TextTokenType.Text);
            else if (Parent is AssemblyTreeNode || assembly.AssemblyDefinition == null)
                output.Write(UIUtils.CleanUpName(assembly.ModuleDefinition.Name), TextTokenType.Module);
            else {
                var asm = assembly.AssemblyDefinition;

                bool isExe = (assembly.ModuleDefinition.Characteristics & dnlib.PE.Characteristics.Dll) == 0;
                output.Write(asm.Name, isExe ? TextTokenType.AssemblyExe : TextTokenType.Assembly);

                bool showAsmVer = DisplaySettingsPanel.CurrentDisplaySettings.ShowAssemblyVersion;
                bool showPublicKeyToken = DisplaySettingsPanel.CurrentDisplaySettings.ShowAssemblyPublicKeyToken && !PublicKeyBase.IsNullOrEmpty2(asm.PublicKeyToken);

                if (showAsmVer || showPublicKeyToken) {
                    output.WriteSpace();
                    output.Write('(', TextTokenType.Operator);

                    bool needComma = false;
                    if (showAsmVer) {
                        if (needComma) {
                            output.Write(',', TextTokenType.Operator);
                            output.WriteSpace();
                        }
                        needComma = true;

                        output.Write(asm.Version.Major.ToString(), TextTokenType.Number);
                        output.Write('.', TextTokenType.Operator);
                        output.Write(asm.Version.Minor.ToString(), TextTokenType.Number);
                        output.Write('.', TextTokenType.Operator);
                        output.Write(asm.Version.Build.ToString(), TextTokenType.Number);
                        output.Write('.', TextTokenType.Operator);
                        output.Write(asm.Version.Revision.ToString(), TextTokenType.Number);
                    }

                    if (showPublicKeyToken) {
                        if (needComma) {
                            output.Write(',', TextTokenType.Operator);
                            output.WriteSpace();
                        }
                        needComma = true;

                        var pkt = asm.PublicKeyToken;
                        if (PublicKeyBase.IsNullOrEmpty2(pkt))
                            output.Write("null", TextTokenType.Keyword);
                        else
                            output.Write(pkt.ToString(), TextTokenType.Number);
                    }

                    output.Write(')', TextTokenType.Operator);
                }
            }
        }
Esempio n. 52
0
 bool WriteRefIfByRef(ITextOutput output, TypeSig typeSig, ParamDef pd)
 {
     if (typeSig.RemovePinnedAndModifiers() is ByRefSig) {
         if (pd != null && (!pd.IsIn && pd.IsOut)) {
             output.Write("out", TextTokenType.Keyword);
             output.WriteSpace();
         }
         else {
             output.Write("ref", TextTokenType.Keyword);
             output.WriteSpace();
         }
         return true;
     }
     return false;
 }
Esempio n. 53
0
        void WriteToolTip(ITextOutput output, IField field)
        {
            var sig = field.FieldSig;
            var gpContext = GenericParamContext.Create(field.DeclaringType.ResolveTypeDef());
            bool isEnumOwner = gpContext.Type != null && gpContext.Type.IsEnum;

            var fd = field.ResolveFieldDef();
            if (!isEnumOwner) {
                if (fd != null && fd.IsLiteral)
                    output.Write("(constant)", TextTokenType.Text);
                else
                    output.Write("(field)", TextTokenType.Text);
                output.WriteSpace();
                WriteToolTip(output, sig.Type, gpContext, null);
                output.WriteSpace();
            }
            WriteToolTip(output, field.DeclaringType);
            output.Write('.', TextTokenType.Operator);
            output.Write(IdentifierEscaper.Escape(field.Name), TextTokenHelper.GetTextTokenType(field));
            if (fd.IsLiteral && fd.Constant != null) {
                output.WriteSpace();
                output.Write('=', TextTokenType.Operator);
                output.WriteSpace();
                WriteToolTipConstant(output, fd.Constant.Value);
            }
        }
Esempio n. 54
0
		public virtual void WriteToolTip(ITextOutput output, IVariable variable, string name)
		{
			output.Write(variable is Local ? "(local variable)" : "(parameter)", TextTokenType.Text);
			output.WriteSpace();
			WriteToolTip(output, variable.Type.ToTypeDefOrRef(), variable is Parameter ? ((Parameter)variable).ParamDef : null);
			output.WriteSpace();
			output.Write(IdentifierEscaper.Escape(GetName(variable, name)), variable is Local ? TextTokenType.Local : TextTokenType.Parameter);
		}
Esempio n. 55
0
		void WriteNamespaceName(ITextOutput output, int nsIndex, int nameIndex) {
			var ns = ReadStringsHeap(nsIndex);
			var name = ReadStringsHeap(nameIndex);

			output.Write(name, TextTokenType.Type);

			if (!string.IsNullOrEmpty(ns)) {
				output.WriteSpace();
				output.Write('-', TextTokenType.Operator);
				output.WriteSpace();

				var parts = ns.Split('.');
				for (int i = 0; i < parts.Length; i++) {
					output.Write(parts[i], TextTokenType.NamespacePart);
					if (i + 1 < parts.Length)
						output.Write('.', TextTokenType.Operator);
				}
			}
		}
Esempio n. 56
0
		void StartKeywordBlock(ITextOutput output, string keyword, IMemberDef member)
		{
			output.Write(keyword, TextTokenType.Keyword);
			output.WriteSpace();
			output.WriteDefinition(IdentifierEscaper.Escape(member.Name), member, TextTokenHelper.GetTextTokenType(member), false);
			output.WriteSpace();
			output.WriteLeftBrace();
			output.WriteLine();
			output.Indent();
		}
Esempio n. 57
0
        public static void WriteOperand(ITextOutput writer, object operand, MethodDef method = null)
        {
            Instruction targetInstruction = operand as Instruction;
            if (targetInstruction != null) {
                WriteOffsetReference(writer, targetInstruction, method);
                return;
            }

            IList<Instruction> targetInstructions = operand as IList<Instruction>;
            if (targetInstructions != null) {
                WriteLabelList(writer, targetInstructions, method);
                return;
            }

            Local variable = operand as Local;
            if (variable != null) {
                if (string.IsNullOrEmpty(variable.Name))
                    writer.WriteReference(variable.Index.ToString(), variable, TextTokenType.Number);
                else
                    writer.WriteReference(Escape(variable.Name), variable, TextTokenType.Local);
                return;
            }

            Parameter paramRef = operand as Parameter;
            if (paramRef != null) {
                if (string.IsNullOrEmpty(paramRef.Name)) {
                    if (paramRef.IsHiddenThisParameter)
                        writer.WriteReference("<hidden-this>", paramRef, TextTokenType.Parameter);
                    else
                        writer.WriteReference(paramRef.MethodSigIndex.ToString(), paramRef, TextTokenType.Parameter);
                }
                else
                    writer.WriteReference(Escape(paramRef.Name), paramRef, TextTokenType.Parameter);
                return;
            }

            MemberRef memberRef = operand as MemberRef;
            if (memberRef != null) {
                if (memberRef.IsMethodRef)
                    memberRef.WriteMethodTo(writer);
                else
                    memberRef.WriteFieldTo(writer);
                return;
            }

            MethodDef methodDef = operand as MethodDef;
            if (methodDef != null) {
                methodDef.WriteMethodTo(writer);
                return;
            }

            FieldDef fieldDef = operand as FieldDef;
            if (fieldDef != null) {
                fieldDef.WriteFieldTo(writer);
                return;
            }

            ITypeDefOrRef typeRef = operand as ITypeDefOrRef;
            if (typeRef != null) {
                typeRef.WriteTo(writer, ILNameSyntax.TypeName);
                return;
            }

            IMethod m = operand as IMethod;
            if (m != null) {
                m.WriteMethodTo(writer);
                return;
            }

            MethodSig sig = operand as MethodSig;
            if (sig != null) {
                sig.WriteTo(writer);
                return;
            }

            string s = operand as string;
            if (s != null) {
                writer.Write("\"" + NRefactory.CSharp.TextWriterTokenWriter.ConvertString(s) + "\"", TextTokenType.String);
            } else if (operand is char) {
                writer.Write(((int)(char)operand).ToString(), TextTokenType.Number);
            } else if (operand is float) {
                float val = (float)operand;
                if (val == 0) {
                    if (1 / val == float.NegativeInfinity) {
                        // negative zero is a special case
                        writer.Write("-0.0", TextTokenType.Number);
                    }
                    else
                        writer.Write("0.0", TextTokenType.Number);
                } else if (float.IsInfinity(val) || float.IsNaN(val)) {
                    byte[] data = BitConverter.GetBytes(val);
                    writer.Write('(', TextTokenType.Operator);
                    for (int i = 0; i < data.Length; i++) {
                        if (i > 0)
                            writer.WriteSpace();
                        writer.Write(data[i].ToString("X2"), TextTokenType.Number);
                    }
                    writer.Write(')', TextTokenType.Operator);
                } else {
                    writer.Write(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture), TextTokenType.Number);
                }
            } else if (operand is double) {
                double val = (double)operand;
                if (val == 0) {
                    if (1 / val == double.NegativeInfinity) {
                        // negative zero is a special case
                        writer.Write("-0.0", TextTokenType.Number);
                    }
                    else
                        writer.Write("0.0", TextTokenType.Number);
                } else if (double.IsInfinity(val) || double.IsNaN(val)) {
                    byte[] data = BitConverter.GetBytes(val);
                    writer.Write('(', TextTokenType.Operator);
                    for (int i = 0; i < data.Length; i++) {
                        if (i > 0)
                            writer.WriteSpace();
                        writer.Write(data[i].ToString("X2"), TextTokenType.Number);
                    }
                    writer.Write(')', TextTokenType.Operator);
                } else {
                    writer.Write(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture), TextTokenType.Number);
                }
            } else if (operand is bool) {
                writer.Write((bool)operand ? "true" : "false", TextTokenType.Keyword);
            } else {
                s = ToInvariantCultureString(operand);
                writer.Write(s, TextTokenHelper.GetTextTokenType(operand));
            }
        }
Esempio n. 58
0
        public static void WriteTo(this Instruction instruction, ITextOutput writer, DisassemblerOptions options, uint baseRva, long baseOffs, IInstructionBytesReader byteReader, MethodDef method)
        {
            if (options != null && (options.ShowTokenAndRvaComments || options.ShowILBytes)) {
                writer.Write("/* ", TextTokenType.Comment);

                bool needSpace = false;

                if (options.ShowTokenAndRvaComments) {
                    ulong fileOffset = (ulong)baseOffs + instruction.Offset;
                    writer.WriteReference(string.Format("0x{0:X8}", fileOffset), new AddressReference(options.OwnerModule == null ? null : options.OwnerModule.Location, false, fileOffset, (ulong)instruction.GetSize()), TextTokenType.Comment, false);
                    needSpace = true;
                }

                if (options.ShowILBytes) {
                    if (needSpace)
                        writer.Write(' ', TextTokenType.Comment);
                    if (byteReader == null)
                        writer.Write("??", TextTokenType.Comment);
                    else {
                        int size = instruction.GetSize();
                        for (int i = 0; i < size; i++) {
                            var b = byteReader.ReadByte();
                            if (b < 0)
                                writer.Write("??", TextTokenType.Comment);
                            else
                                writer.Write(string.Format("{0:X2}", b), TextTokenType.Comment);
                        }
                        // Most instructions should be at most 5 bytes in length, but use 6 since
                        // ldftn/ldvirtftn are 6 bytes long. The longest instructions are those with
                        // 8 byte operands, ldc.i8 and ldc.r8: 9 bytes.
                        const int MIN_BYTES = 6;
                        for (int i = size; i < MIN_BYTES; i++)
                            writer.Write("  ", TextTokenType.Comment);
                    }
                }

                writer.Write(" */", TextTokenType.Comment);
                writer.WriteSpace();
            }
            writer.WriteDefinition(DnlibExtensions.OffsetToString(instruction.GetOffset()), new InstructionReference(method, instruction), TextTokenType.Label, false);
            writer.Write(':', TextTokenType.Operator);
            writer.WriteSpace();
            writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, TextTokenType.OpCode);
            if (instruction.Operand != null) {
                int count = OPERAND_ALIGNMENT - instruction.OpCode.Name.Length;
                if (count <= 0)
                    count = 1;
                writer.Write(spaces[count], TextTokenType.Text);
                if (instruction.OpCode == OpCodes.Ldtoken) {
                    var member = instruction.Operand as IMemberRef;
                    if (member != null && member.IsMethod) {
                        writer.Write("method", TextTokenType.Keyword);
                        writer.WriteSpace();
                    }
                    else if (member != null && member.IsField) {
                        writer.Write("field", TextTokenType.Keyword);
                        writer.WriteSpace();
                    }
                }
                WriteOperand(writer, instruction.Operand, method);
            }
            if (options != null && options.GetOpCodeDocumentation != null) {
                var doc = options.GetOpCodeDocumentation(instruction.OpCode);
                if (doc != null) {
                    writer.Write("\t", TextTokenType.Text);
                    writer.Write("// " + doc, TextTokenType.Comment);
                }
            }
        }
Esempio n. 59
0
        void WriteToolTip(ITextOutput output, PropertyDef prop)
        {
            var sig = prop.PropertySig;
            var md = prop.GetMethods.FirstOrDefault() ??
                    prop.SetMethods.FirstOrDefault() ??
                    prop.OtherMethods.FirstOrDefault();

            var writer = new MethodWriter(this, output, md);
            writer.WriteReturnType();
            WriteToolTip(output, prop.DeclaringType);
            output.Write('.', TextTokenType.Operator);
            var ovrMeth = md == null || md.Overrides.Count == 0 ? null : md.Overrides[0].MethodDeclaration;
            if (prop.IsIndexer()) {
                if (ovrMeth != null) {
                    WriteToolTipType(output, ovrMeth.DeclaringType, false);
                    output.Write('.', TextTokenType.Operator);
                }
                output.Write("this", TextTokenType.Keyword);
                writer.WriteGenericArguments();
                writer.WriteMethodParameterList('[', ']');
            }
            else if (ovrMeth != null && GetPropName(ovrMeth) != null) {
                WriteToolTipType(output, ovrMeth.DeclaringType, false);
                output.Write('.', TextTokenType.Operator);
                output.Write(IdentifierEscaper.Escape(GetPropName(ovrMeth)), TextTokenHelper.GetTextTokenType(prop));
            }
            else
                output.Write(IdentifierEscaper.Escape(prop.Name), TextTokenHelper.GetTextTokenType(prop));

            output.WriteSpace();
            output.WriteLeftBrace();
            if (prop.GetMethods.Count > 0) {
                output.WriteSpace();
                output.Write("get", TextTokenType.Keyword);
                output.Write(';', TextTokenType.Operator);
            }
            if (prop.SetMethods.Count > 0) {
                output.WriteSpace();
                output.Write("set", TextTokenType.Keyword);
                output.Write(';', TextTokenType.Operator);
            }
            output.WriteSpace();
            output.WriteRightBrace();
        }