internal static IReadOnlyList <Element> Prettify(DisassembledMethod method, string labelPrefix) { var parsed = method.Maps.SelectMany(map => map.Instructions.Select(Parse)).ToArray(); // if somebody is using given address as arugment, the address is "used" and should have it's own label var usedArguments = new HashSet <string>(parsed .Select( a => string.IsNullOrEmpty(a.extraArguments) ? a.arguments : a.extraArguments) .Where(arguments => !string.IsNullOrEmpty(arguments)).Distinct()); var addressesToLabels = new Dictionary <string, string>(); int currentLabelIndex = 0; foreach (var instruction in parsed) { if (usedArguments.Contains(instruction.address) && !addressesToLabels.ContainsKey(instruction.address)) { addressesToLabels.Add(instruction.address, $"{labelPrefix}_L{currentLabelIndex++:00}"); } } var prettified = new List <Element>(); foreach (var instruction in parsed) { if (!(instruction.source is Asm)) { prettified.Add(new Element(instruction.source.TextRepresentation, instruction.source)); continue; } if (addressesToLabels.TryGetValue(instruction.address, out var label)) { prettified.Add(new Label(label, label)); } var argument = string.IsNullOrEmpty(instruction.extraArguments) ? instruction.arguments : instruction.extraArguments; if (addressesToLabels.TryGetValue(argument, out var reference)) // it's sth like 00007ff7`ffbfd320 7cba jl 00007ff7`ffbfd2dc { prettified.Add(new Reference($"{PadRight(instruction.instruction)} {reference}", reference, instruction.source)); } else if (!string.IsNullOrEmpty(instruction.extraArguments) && !instruction.extraArguments.StartsWith("(")) { prettified.Add(new Element($"{PadRight(instruction.instruction)} {instruction.arguments} {WithoutAddress(instruction.extraArguments)}", instruction.source)); } else if (!string.IsNullOrEmpty(instruction.arguments)) { prettified.Add(new Element($"{PadRight(instruction.instruction)} {instruction.arguments}", instruction.source)); } else // sth like "ret" { prettified.Add(new Element(instruction.instruction, instruction.source)); } } return(prettified); }
public DisassemblyResult() { Methods = new DisassembledMethod[0]; Errors = new string[0]; }