namespace X86Disassembler.Analysers; /// /// Represents a disassembled function with its control flow graph /// public class AsmFunction { /// /// The starting address of the function /// public ulong Address { get; set; } /// /// The list of basic blocks that make up the function /// public List Blocks { get; set; } = []; /// /// The entry block of the function /// public InstructionBlock? EntryBlock => Blocks.FirstOrDefault(b => b.Address == Address); /// /// The exit blocks of the function (blocks that end with a return instruction) /// public List ExitBlocks => Blocks.Where(b => b.Instructions.Count > 0 && b.Instructions[^1].Type.IsRet()).ToList(); /// /// Returns a string representation of the function, including its address and blocks /// public override string ToString() { return $"Function at 0x{Address:X8}\n" + $"Entry Block: 0x{EntryBlock?.Address.ToString("X8") ?? "None"}\n" + $"Exit Blocks: {(ExitBlocks.Count > 0 ? string.Join(", ", ExitBlocks.Select(b => $"0x{b.Address:X8}")) : "None")}\n" + $"Total Blocks: {Blocks.Count}\n" + $"{string.Join("\n", Blocks.Select(x => $"\t{x}"))}"; } }