コード例 #1
0
ファイル: TableEntry.cs プロジェクト: mattweb28/pspplayer
 public InstructionEntry(string name, InstructionFormatter formatter, uint flags)
 {
     this.Name      = name;
     this.Formatter = formatter;
     this.Flags     = flags;
 }
コード例 #2
0
        internal static IReadOnlyList <Element> Prettify(DisassembledMethod method, DisassemblyResult disassemblyResult, DisassemblyDiagnoserConfig config, string labelPrefix)
        {
            var asmInstructions = method.Maps.SelectMany(map => map.SourceCodes.OfType <Asm>()).ToArray();

            // first of all, we search of referenced addresses (jump|calls)
            var referencedAddresses = new HashSet <ulong>();

            foreach (var asm in asmInstructions)
            {
                if (ClrMdV2Disassembler.TryGetReferencedAddress(asm.Instruction, disassemblyResult.PointerSize, out ulong referencedAddress))
                {
                    referencedAddresses.Add(referencedAddress);
                }
            }

            // for every IP that is referenced, we emit a uinque label
            var addressesToLabels = new Dictionary <ulong, string>();
            int currentLabelIndex = 0;

            foreach (var instruction in asmInstructions)
            {
                if (referencedAddresses.Contains(instruction.InstructionPointer) && !addressesToLabels.ContainsKey(instruction.InstructionPointer))
                {
                    addressesToLabels.Add(instruction.InstructionPointer, $"{labelPrefix}_L{currentLabelIndex++:00}");
                }
            }

            var formatterWithLabelsSymbols = config.GetFormatterWithSymbolSolver(addressesToLabels);
            var formatterWithGlobalSymbols = config.GetFormatterWithSymbolSolver(disassemblyResult.AddressToNameMapping);

            var prettified = new List <Element>();

            foreach (var map in method.Maps)
            {
                foreach (var instruction in map.SourceCodes)
                {
                    if (instruction is Sharp sharp)
                    {
                        prettified.Add(new Element(sharp.Text, sharp));
                    }
                    else if (instruction is MonoCode mono)
                    {
                        prettified.Add(new Element(mono.Text, mono));
                    }
                    else if (instruction is Asm asm)
                    {
                        // this IP is referenced by some jump|call, so we add a label
                        if (addressesToLabels.TryGetValue(asm.InstructionPointer, out string label))
                        {
                            prettified.Add(new Label(label));
                        }

                        if (ClrMdV2Disassembler.TryGetReferencedAddress(asm.Instruction, disassemblyResult.PointerSize, out ulong referencedAddress))
                        {
                            // jump or a call within same method
                            if (addressesToLabels.TryGetValue(referencedAddress, out string translated))
                            {
                                prettified.Add(new Reference(InstructionFormatter.Format(asm.Instruction, formatterWithLabelsSymbols, config.PrintInstructionAddresses, disassemblyResult.PointerSize), translated, asm));
                                continue;
                            }

                            // call to a known method
                            if (disassemblyResult.AddressToNameMapping.ContainsKey(referencedAddress))
                            {
                                prettified.Add(new Element(InstructionFormatter.Format(asm.Instruction, formatterWithGlobalSymbols, config.PrintInstructionAddresses, disassemblyResult.PointerSize), asm));
                                continue;
                            }
                        }

                        prettified.Add(new Element(InstructionFormatter.Format(asm.Instruction, formatterWithGlobalSymbols, config.PrintInstructionAddresses, disassemblyResult.PointerSize), asm));
                    }
                }
            }

            return(prettified);
        }
コード例 #3
0
ファイル: TableEntry.cs プロジェクト: BradFuller/pspplayer
		public InstructionEntry( string name, InstructionFormatter formatter, uint flags )
		{
			this.Name = name;
			this.Formatter = formatter;
			this.Flags = flags;
		}
コード例 #4
0
        public string ToString(IBuddyTranslationInstruction translationInstruction, IDictionary <string, IPatternParameter> parameters)
        {
            InstructionFormatter instructionFormatter = new InstructionFormatter();

            return(instructionFormatter.ToString(translationInstruction, parameters));
        }
コード例 #5
0
ファイル: Instruction.cs プロジェクト: andy-uq/TinyOS
 public override string ToString()
 {
     return(InstructionFormatter.ToString(this).TrimEnd());
 }