public InstructionEntry(string name, InstructionFormatter formatter, uint flags) { this.Name = name; this.Formatter = formatter; this.Flags = flags; }
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); }
public InstructionEntry( string name, InstructionFormatter formatter, uint flags ) { this.Name = name; this.Formatter = formatter; this.Flags = flags; }
public string ToString(IBuddyTranslationInstruction translationInstruction, IDictionary <string, IPatternParameter> parameters) { InstructionFormatter instructionFormatter = new InstructionFormatter(); return(instructionFormatter.ToString(translationInstruction, parameters)); }
public override string ToString() { return(InstructionFormatter.ToString(this).TrimEnd()); }