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)); }