本文整理汇总了C#中ITextOutput.WriteDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextOutput.WriteDefinition方法的具体用法?C# ITextOutput.WriteDefinition怎么用?C# ITextOutput.WriteDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextOutput
的用法示例。
在下文中一共展示了ITextOutput.WriteDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecompileMethod
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);
}
示例2: WriteTo
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);
}
}
}
示例3: DecompileMethod
public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
if (!method.HasBody) {
return;
}
ILAstBuilder astBuilder = new ILAstBuilder();
ILBlock ilMethod = new ILBlock();
ilMethod.Body = astBuilder.Build(method, inlineVariables);
if (abortBeforeStep != null) {
DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
}
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(v.Name, v);
if (v.Type != null) {
output.Write(" : ");
if (v.IsPinned)
output.Write("pinned ");
v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
}
output.WriteLine();
}
output.WriteLine();
foreach (ILNode node in ilMethod.Body) {
node.WriteTo(output);
output.WriteLine();
}
}
示例4: WriteTo
public static void WriteTo(this Instruction instruction, ITextOutput writer)
{
writer.WriteDefinition(CecilExtensions.OffsetToString(instruction.Offset), instruction);
writer.Write(": ");
writer.WriteReference(instruction.OpCode.Name, instruction.OpCode);
if(null != instruction.Operand) {
writer.Write(' ');
WriteOperand(writer, instruction.Operand);
}
}
示例5: WriteTo
public static void WriteTo(this Instruction instruction, ITextOutput writer)
{
writer.WriteDefinition(CecilExtensions.OffsetToString(instruction.Offset), instruction);
writer.Write(": ");
writer.WriteReference(instruction.OpCode.Name, instruction.OpCode);
if (instruction.Operand != null) {
writer.Write(' ');
if (instruction.OpCode == OpCodes.Ldtoken) {
if (instruction.Operand is MethodReference)
writer.Write("method ");
else if (instruction.Operand is FieldReference)
writer.Write("field ");
}
WriteOperand(writer, instruction.Operand);
}
}
示例6: WriteTo
public static void WriteTo(this Instruction instruction, MethodDef method, CilBody body, ITextOutput writer)
{
writer.WriteDefinition(dnlibExtensions.OffsetToString(instruction.Offset), instruction, true);
writer.Write(": ");
writer.WriteReference(instruction.OpCode.Name, instruction.OpCode, true);
if (instruction.Operand != null) {
writer.Write(' ');
if (instruction.OpCode == OpCodes.Ldtoken) {
if (dnlibExtensions.IsMethod(instruction.Operand))
writer.WriteKeyword("method ");
else if (dnlibExtensions.IsField(instruction.Operand))
writer.WriteKeyword("field ");
}
WriteOperand(writer, instruction.Operand);
}
else if (method != null && body != null) {
switch (instruction.OpCode.Code) {
case Code.Ldloc_0:
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
writer.WriteComment(" // ");
var local = instruction.GetLocal(body.Variables);
if (local != null)
WriteOperand(writer, local);
break;
case Code.Ldarg_0:
case Code.Ldarg_1:
case Code.Ldarg_2:
case Code.Ldarg_3:
writer.WriteComment(" // ");
var arg = instruction.GetParameter(method.Parameters);
if (arg != null)
WriteOperand(writer, arg);
break;
}
}
}
示例7: DecompileField
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;
}
}
}
}
示例8: StartKeywordBlock
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();
}
示例9: WriteTo
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);
}
}
}
示例10: WriteShort
public override void WriteShort(ITextOutput output, ILanguage language, bool showOffset)
{
var smartOutput = output as ISmartTextOutput;
if (smartOutput != null) {
language.WriteCommentBegin(output, true);
output.WriteOffsetComment(this, showOffset);
smartOutput.AddUIElement(() => {
return new System.Windows.Controls.Image {
Source = imageSource,
};
});
output.Write(" = ", TextTokenKind.Comment);
output.WriteDefinition(NameUtils.CleanName(Name), this, TextTokenKind.Comment);
language.WriteCommentEnd(output, true);
output.WriteLine();
return;
}
base.WriteShort(output, language, showOffset);
}
示例11: Decompile
public virtual void Decompile(Language language, ITextOutput output) {
language.WriteComment(output, string.Empty);
output.WriteOffsetComment(this);
output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
string extra = null;
if (r.ResourceType == ResourceType.AssemblyLinked)
extra = ((AssemblyLinkedResource)r).Assembly.FullName;
else if (r.ResourceType == ResourceType.Linked) {
var file = ((LinkedResource)r).File;
extra = string.Format("{0}, {1}, {2}", file.Name, file.ContainsNoMetaData ? "ContainsNoMetaData" : "ContainsMetaData", NumberVMUtils.ByteArrayToString(file.HashValue));
}
else if (r.ResourceType == ResourceType.Embedded)
extra = string.Format("{0} bytes", ((EmbeddedResource)r).Data.Length);
output.Write(string.Format(" ({0}{1}, {2})", extra == null ? string.Empty : string.Format("{0}, ", extra), r.ResourceType, r.Attributes), TextTokenType.Comment);
output.WriteLine();
}
示例12: Decompile
public virtual void Decompile(Language language, ITextOutput output)
{
language.WriteComment(output, string.Empty);
output.WriteOffsetComment(this);
output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
output.Write(string.Format(" = {0}", ValueString), TextTokenType.Comment);
output.WriteLine();
}
示例13: WriteShort
public virtual void WriteShort(ITextOutput output, ILanguage language, bool showOffset)
{
language.WriteCommentBegin(output, true);
output.WriteOffsetComment(this, showOffset);
output.WriteDefinition(NameUtils.CleanName(Name), this, TextTokenKind.Comment);
output.Write(string.Format(" = {0}", ValueString), TextTokenKind.Comment);
language.WriteCommentEnd(output, true);
output.WriteLine();
}
示例14: Decompile
public virtual void Decompile(Language language, ITextOutput output)
{
language.WriteComment(output, string.Empty);
if (Options.DecompilerSettingsPanel.CurrentDecompilerSettings.ShowTokenAndRvaComments) {
long fo = FileOffset;
if (fo != 0)
output.Write(string.Format("0x{0:X8}: ", fo), TextTokenType.Comment);
}
output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
output.Write(string.Format(" = {0}", ValueString), TextTokenType.Comment);
output.WriteLine();
}
示例15: Decompile
public virtual void Decompile(Language language, ITextOutput output)
{
language.WriteComment(output, string.Empty);
if (Options.DecompilerSettingsPanel.CurrentDecompilerSettings.ShowTokenAndRvaComments) {
long fo = FileOffset;
if (fo != 0)
output.Write(string.Format("0x{0:X8}: ", fo), TextTokenType.Comment);
}
output.WriteDefinition(UIUtils.CleanUpName(Name), this, TextTokenType.Comment);
string extra = null;
if (r.ResourceType == ResourceType.AssemblyLinked)
extra = ((AssemblyLinkedResource)r).Assembly.FullName;
else if (r.ResourceType == ResourceType.Linked) {
var file = ((LinkedResource)r).File;
extra = string.Format("{0}, {1}, {2}", file.Name, file.ContainsNoMetaData ? "ContainsNoMetaData" : "ContainsMetaData", AsmEditor.NumberVMUtils.ByteArrayToString(file.HashValue));
}
output.Write(string.Format(" ({0}{1}, {2})", extra == null ? string.Empty : string.Format("{0}, ", extra), r.ResourceType, r.Attributes), TextTokenType.Comment);
output.WriteLine();
}