Beispiel #1
0
        ReflectionDisassembler CreateReflectionDisassembler(ITextOutput output, DecompilationContext ctx, ModuleDef ownerModule)
        {
            var disOpts = new DisassemblerOptions(ctx.CancellationToken, ownerModule);

            if (langSettings.Settings.ShowILComments)
            {
                disOpts.GetOpCodeDocumentation = ILLanguageHelper.GetOpCodeDocumentation;
            }
            if (langSettings.Settings.ShowXmlDocumentation)
            {
                disOpts.GetXmlDocComments = GetXmlDocComments;
            }
            disOpts.CreateInstructionBytesReader = m => InstructionBytesReader.Create(m, ctx.IsBodyModified != null && ctx.IsBodyModified(m));
            disOpts.ShowTokenAndRvaComments      = langSettings.Settings.ShowTokenAndRvaComments;
            disOpts.ShowILBytes = langSettings.Settings.ShowILBytes;
            disOpts.SortMembers = langSettings.Settings.SortMembers;
            return(new ReflectionDisassembler(output, detectControlStructure, disOpts));
        }
Beispiel #2
0
        ReflectionDisassembler CreateReflectionDisassembler(IDecompilerOutput output, DecompilationContext ctx, ModuleDef ownerModule)
        {
            var disOpts = new DisassemblerOptions(langSettings.Settings.SettingsVersion, ctx.CancellationToken, ownerModule);

            if (langSettings.Settings.ShowILComments)
            {
                disOpts.GetOpCodeDocumentation = ILLanguageHelper.GetOpCodeDocumentation;
            }
            var sb = new StringBuilder();

            if (langSettings.Settings.ShowXmlDocumentation)
            {
                disOpts.GetXmlDocComments = a => GetXmlDocComments(a, sb);
            }
            disOpts.CreateInstructionBytesReader = m => InstructionBytesReader.Create(m, !(ctx.IsBodyModified is null) && ctx.IsBodyModified(m));
            disOpts.ShowTokenAndRvaComments      = langSettings.Settings.ShowTokenAndRvaComments;
            disOpts.ShowILBytes     = langSettings.Settings.ShowILBytes;
            disOpts.SortMembers     = langSettings.Settings.SortMembers;
            disOpts.ShowPdbInfo     = langSettings.Settings.ShowPdbInfo;
            disOpts.MaxStringLength = langSettings.Settings.MaxStringLength;
            return(new ReflectionDisassembler(output, detectControlStructure, disOpts));
        }
Beispiel #3
0
        public string Copy(IEnumerable <SpanData <ReferenceInfo> > refs, Lazy <IMethodAnnotations> methodAnnotations)
        {
            var sb = new StringBuilder();

            IInstructionBytesReader reader = null;

            try {
                MethodDef method = null;
                int       index  = 0;
                foreach (var r in refs)
                {
                    var ir    = (InstructionReference)r.Data.Reference;
                    var instr = ir.Instruction;
                    if (ir.Method != method)
                    {
                        if (reader != null)
                        {
                            reader.Dispose();
                        }
                        method = ir.Method;
                        reader = InstructionBytesReader.Create(method, methodAnnotations.Value.IsBodyModified(method));
                        index  = method.Body.Instructions.IndexOf(instr);
                        if (index < 0)
                        {
                            throw new InvalidOperationException();
                        }
                        reader.SetInstruction(index, instr.Offset);
                    }
                    else if (index >= method.Body.Instructions.Count)
                    {
                        throw new InvalidOperationException();
                    }
                    else if (method.Body.Instructions[index + 1] != ir.Instruction)
                    {
                        index = method.Body.Instructions.IndexOf(instr);
                        if (index < 0)
                        {
                            throw new InvalidOperationException();
                        }
                        reader.SetInstruction(index, instr.Offset);
                    }
                    else
                    {
                        index++;
                    }

                    int size = instr.GetSize();
                    for (int i = 0; i < size; i++)
                    {
                        int b = reader.ReadByte();
                        if (b < 0)
                        {
                            sb.Append("??");
                            FoundUnknownBytes = true;
                        }
                        else
                        {
                            sb.Append(string.Format("{0:X2}", b));
                        }
                    }
                }
            }
            finally {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }

            return(sb.ToString());
        }