mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-07-01 20:40:27 +03:00
decompiler iter1
This commit is contained in:
@ -26,16 +26,62 @@ public class AsmFunction
|
||||
public List<InstructionBlock> ExitBlocks => Blocks.Where(b =>
|
||||
b.Instructions.Count > 0 &&
|
||||
b.Instructions[^1].Type.IsRet()).ToList();
|
||||
|
||||
/// <summary>
|
||||
/// The analyzer context for this function
|
||||
/// </summary>
|
||||
public AnalyzerContext Context { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new AsmFunction instance
|
||||
/// </summary>
|
||||
public AsmFunction()
|
||||
{
|
||||
Context = new AnalyzerContext(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Analyzes the function using various analyzers
|
||||
/// </summary>
|
||||
public void Analyze()
|
||||
{
|
||||
// Analyze loops
|
||||
var loopAnalyzer = new LoopAnalyzer();
|
||||
loopAnalyzer.AnalyzeLoops(Context);
|
||||
|
||||
// Analyze data flow
|
||||
var dataFlowAnalyzer = new DataFlowAnalyzer();
|
||||
dataFlowAnalyzer.AnalyzeDataFlow(Context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the function, including its address and blocks
|
||||
/// Returns a string representation of the function, including its address, blocks, and analysis results
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
string loopsInfo = "";
|
||||
if (Context.LoopsByHeaderAddress.Count > 0)
|
||||
{
|
||||
loopsInfo = $"Loops: {Context.LoopsByHeaderAddress.Count}\n";
|
||||
int i = 0;
|
||||
foreach (var loop in Context.LoopsByHeaderAddress.Values)
|
||||
{
|
||||
loopsInfo += $" Loop {i++}: Header=0x{loop.Header.Address:X8}, " +
|
||||
$"Blocks={loop.Blocks.Count}, " +
|
||||
$"Back Edge=(0x{loop.BackEdge.From.Address:X8} -> 0x{loop.BackEdge.To.Address:X8}), " +
|
||||
$"Exits={loop.ExitBlocks.Count}\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
loopsInfo = "Loops: None\n";
|
||||
}
|
||||
|
||||
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" +
|
||||
loopsInfo +
|
||||
$"{string.Join("\n", Blocks.Select(x => $"\t{x}"))}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user