public void TestSequenceBackwardsMatch() { ILPattern sequence = ILPattern.Sequence(OpCodes.Stsfld, OpCodes.Ldsfld); MethodDefinition method = CreateTestMethod(TestSequence1); Instruction lastInstruction = LastInstruction(method); ILPattern.MatchContext context = sequence.BackwardsMatch(lastInstruction); Assert.IsTrue(context.Success); Assert.AreSame(method.Body.Instructions[0], context.Instruction); }
public void TestSequenceIsBackwardsMatch() { ILPattern sequence = ILPattern.Sequence(OpCodes.Stsfld, OpCodes.Ldsfld); Instruction lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence1); Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction)); sequence = ILPattern.Sequence(OpCodes.Ldsfld, OpCodes.Stsfld); Assert.IsTrue(!sequence.IsBackwardsMatch(lastInstruction)); }
private static ILPattern CreateStaticFieldPattern() { // ldsfld (br_s)? stsfld newobj ldftn ldnull (brtrue_s | brtrue) ldsfld return(ILPattern.Sequence( ILPattern.Instruction(OpCodes.Ldsfld), ILPattern.Optional(OpCodes.Br_S), ILPattern.Instruction(OpCodes.Stsfld), ILPattern.Instruction(OpCodes.Newobj), ILPattern.Instruction(OpCodes.Ldftn), ILPattern.Instruction(OpCodes.Ldnull), ILPattern.Alternation(OpCodes.Brtrue, OpCodes.Brtrue_S), ILPattern.Instruction(OpCodes.Ldsfld))); }
public void TestComplexSequenceIsBackwardsMatch() { ILPattern sequence = ILPattern.Sequence( ILPattern.Optional(OpCodes.Ret), ILPattern.Instruction(OpCodes.Stsfld), ILPattern.Alternation(OpCodes.Ldfld, OpCodes.Ldsfld)); Instruction lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence1); Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction)); lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence2); Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction)); }