public CILInstruction GetInstructionByBranchTarget(CILInstruction currentInstruction, int branchTarget) { var bytesPosition = GetBytesPosition(GetNextInstruction(currentInstruction)); var newBytesPosition = bytesPosition + branchTarget; return(GetInstructionByBytesPosition(newBytesPosition)); }
private int GetBytesPosition(CILInstruction instruction) { var index = Instructions.IndexOf(instruction); var previousInstructions = Instructions.Take(index); return(previousInstructions.Sum(i => i.BytesLength)); }
public CILInstruction GetNextInstruction(CILInstruction currentInstruction) { var currentIndex = Instructions.IndexOf(currentInstruction); var nextIndex = currentIndex + 1; if (nextIndex >= Instructions.Count) { return(null); } return(Instructions[currentIndex + 1]); }