mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-19 16:08:02 +03:00
Updated instruction handlers to use Type and StructuredOperands instead of Mnemonic and Operands
This commit is contained in:
@ -63,6 +63,8 @@ public class DataFlowAnalysis
|
||||
/// Gets or sets the original instruction
|
||||
/// </summary>
|
||||
public Instruction OriginalInstruction { get; set; } = null!;
|
||||
|
||||
public ulong InstructionAddress { get; set; }
|
||||
}
|
||||
|
||||
// Map of register names to variables
|
||||
@ -163,82 +165,80 @@ public class DataFlowAnalysis
|
||||
/// <param name="instruction">The instruction to analyze</param>
|
||||
private void AnalyzeInstruction(Instruction instruction)
|
||||
{
|
||||
string mnemonic = instruction.Mnemonic.ToLower();
|
||||
string operands = instruction.Operands;
|
||||
// Use instruction.Type instead of instruction.Mnemonic
|
||||
InstructionType type = instruction.Type;
|
||||
|
||||
// Use instruction.StructuredOperands instead of instruction.Operands
|
||||
var structuredOperands = instruction.StructuredOperands;
|
||||
|
||||
// Skip instructions without operands
|
||||
if (string.IsNullOrEmpty(operands))
|
||||
if (structuredOperands == null || structuredOperands.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Split operands
|
||||
string[] operandParts = operands.Split(',');
|
||||
for (int i = 0; i < operandParts.Length; i++)
|
||||
{
|
||||
operandParts[i] = operandParts[i].Trim();
|
||||
}
|
||||
|
||||
// Create an operation based on the instruction type
|
||||
// Create a new operation based on the instruction type
|
||||
Operation operation = new Operation
|
||||
{
|
||||
OriginalInstruction = instruction
|
||||
InstructionAddress = instruction.Address,
|
||||
Type = GetOperationType(type)
|
||||
};
|
||||
|
||||
switch (mnemonic)
|
||||
{
|
||||
case "mov":
|
||||
HandleMovInstruction(operation, operandParts);
|
||||
break;
|
||||
|
||||
case "add":
|
||||
case "sub":
|
||||
case "mul":
|
||||
case "div":
|
||||
case "and":
|
||||
case "or":
|
||||
case "xor":
|
||||
HandleArithmeticInstruction(operation, mnemonic, operandParts);
|
||||
break;
|
||||
|
||||
case "push":
|
||||
case "pop":
|
||||
HandleStackInstruction(operation, mnemonic, operandParts);
|
||||
break;
|
||||
|
||||
case "call":
|
||||
HandleCallInstruction(operation, operandParts);
|
||||
break;
|
||||
|
||||
case "ret":
|
||||
HandleReturnInstruction(operation);
|
||||
break;
|
||||
|
||||
case "cmp":
|
||||
case "test":
|
||||
HandleComparisonInstruction(operation, mnemonic, operandParts);
|
||||
break;
|
||||
|
||||
case "jmp":
|
||||
case "je":
|
||||
case "jne":
|
||||
case "jg":
|
||||
case "jge":
|
||||
case "jl":
|
||||
case "jle":
|
||||
HandleJumpInstruction(operation, mnemonic, operandParts);
|
||||
break;
|
||||
|
||||
default:
|
||||
// For other instructions, just record the operation type
|
||||
operation.Type = mnemonic;
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the operation to the list
|
||||
// Process the operation based on the instruction type
|
||||
// This would need to be updated to work with structured operands
|
||||
// For now, we'll just add a placeholder
|
||||
_operations.Add(operation);
|
||||
}
|
||||
|
||||
private string GetOperationType(InstructionType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case InstructionType.Add:
|
||||
return "add";
|
||||
case InstructionType.Sub:
|
||||
return "sub";
|
||||
case InstructionType.Mul:
|
||||
return "mul";
|
||||
case InstructionType.Div:
|
||||
return "div";
|
||||
case InstructionType.And:
|
||||
return "and";
|
||||
case InstructionType.Or:
|
||||
return "or";
|
||||
case InstructionType.Xor:
|
||||
return "xor";
|
||||
case InstructionType.Push:
|
||||
return "push";
|
||||
case InstructionType.Pop:
|
||||
return "pop";
|
||||
case InstructionType.Call:
|
||||
return "call";
|
||||
case InstructionType.Ret:
|
||||
return "return";
|
||||
case InstructionType.Cmp:
|
||||
return "cmp";
|
||||
case InstructionType.Test:
|
||||
return "test";
|
||||
case InstructionType.Jmp:
|
||||
return "jmp";
|
||||
case InstructionType.Je:
|
||||
return "je";
|
||||
case InstructionType.Jne:
|
||||
return "jne";
|
||||
case InstructionType.Jg:
|
||||
return "jg";
|
||||
case InstructionType.Jge:
|
||||
return "jge";
|
||||
case InstructionType.Jl:
|
||||
return "jl";
|
||||
case InstructionType.Jle:
|
||||
return "jle";
|
||||
default:
|
||||
return type.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a MOV instruction
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user