Package proguard.classfile.util
Class InstructionSequenceMatcher
- java.lang.Object
-
- proguard.classfile.util.InstructionSequenceMatcher
-
- All Implemented Interfaces:
ConstantVisitor,InstructionVisitor
public class InstructionSequenceMatcher extends java.lang.Object implements InstructionVisitor, ConstantVisitor
ThisInstructionVisitorchecks whether a given pattern instruction sequence occurs in the instructions that are visited. The arguments of the instruction sequence can be wildcards that are matched.
-
-
Field Summary
Fields Modifier and Type Field Description static intAstatic intBstatic intCstatic intDstatic intEstatic intFstatic intGstatic intHstatic intIstatic intJstatic intKstatic intLstatic intMprotected booleanmatchingConstantstatic intNstatic intOstatic intPprotected ConstantpatternConstantprotected Constant[]patternConstantsprotected Instruction[]patternInstructionsstatic intQstatic intRstatic intXstatic intYstatic intZ
-
Constructor Summary
Constructors Constructor Description InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions)Creates a new InstructionSequenceMatcher.InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions, boolean matchSubclasses)Creates a new InstructionSequenceMatcher.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanfinalMatch(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction)Performs a final check on the candidate sequence to match, after the pattern has been successfully fully matched with the sequence.intinstructionCount()Returns the number of instructions in the pattern sequence.booleanisMatching()Returns whether the complete pattern sequence has been matched.static voidmain(java.lang.String[] args)Small sample application that illustrates the use of this class.intmatchedArgument(int argument)Returns the value of the specified matched argument (wildcard or not).int[]matchedArguments(int[] arguments)Returns the values of the specified matched arguments (wildcard or not).intmatchedBranchOffset(int offset, int branchOffset)Returns the value of the specified matched branch offset (wildcard or not).intmatchedConstantIndex(int constantIndex)Returns the index of the specified matched constant (wildcard or not).intmatchedInstructionOffset(int index)Returns the matched instruction offset of the specified pattern instruction.int[]matchedJumpOffsets(int offset, int[] jumpOffsets)Returns the values of the specified matched jump offsets (wildcard or not).protected booleanmatchingArguments(int[] arguments1, int[] arguments2)protected booleanmatchingArguments(int argument1, int argument2)protected booleanmatchingBranchOffsets(int offset, int branchOffset1, int branchOffset2)protected booleanmatchingConstantIndices(Clazz clazz, int constantIndex1, int constantIndex2)protected booleanmatchingJumpOffsets(int offset, int[] jumpOffsets1, int[] jumpOffsets2)protected booleanmatchingOpcodes(Instruction instruction1, Instruction instruction2)voidreset()Starts matching from the first instruction again next time.voidvisitAnyRefConstant(Clazz clazz, RefConstant refConstant)Visits any RefConstant instance.voidvisitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)voidvisitClassConstant(Clazz clazz, ClassConstant classConstant)voidvisitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)voidvisitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)voidvisitDynamicConstant(Clazz clazz, DynamicConstant dynamicConstant)voidvisitFloatConstant(Clazz clazz, FloatConstant floatConstant)voidvisitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)voidvisitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)voidvisitLongConstant(Clazz clazz, LongConstant longConstant)voidvisitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction)voidvisitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)voidvisitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)voidvisitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)voidvisitPrimitiveArrayConstant(Clazz clazz, PrimitiveArrayConstant primitiveArrayConstant)voidvisitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)voidvisitStringConstant(Clazz clazz, StringConstant stringConstant)voidvisitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction)voidvisitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)voidvisitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)booleanwasConstant(int argument)Returns whether the specified wildcard argument was a constant from the constant pool in the most recent match.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface proguard.classfile.constant.visitor.ConstantVisitor
visitAnyConstant, visitAnyMethodrefConstant, visitFieldrefConstant, visitInterfaceMethodrefConstant, visitMethodrefConstant, visitModuleConstant, visitPackageConstant
-
Methods inherited from interface proguard.classfile.instruction.visitor.InstructionVisitor
visitAnyInstruction, visitAnySwitchInstruction
-
-
-
-
Field Detail
-
X
public static final int X
- See Also:
- Constant Field Values
-
Y
public static final int Y
- See Also:
- Constant Field Values
-
Z
public static final int Z
- See Also:
- Constant Field Values
-
A
public static final int A
- See Also:
- Constant Field Values
-
B
public static final int B
- See Also:
- Constant Field Values
-
C
public static final int C
- See Also:
- Constant Field Values
-
D
public static final int D
- See Also:
- Constant Field Values
-
E
public static final int E
- See Also:
- Constant Field Values
-
F
public static final int F
- See Also:
- Constant Field Values
-
G
public static final int G
- See Also:
- Constant Field Values
-
H
public static final int H
- See Also:
- Constant Field Values
-
I
public static final int I
- See Also:
- Constant Field Values
-
J
public static final int J
- See Also:
- Constant Field Values
-
K
public static final int K
- See Also:
- Constant Field Values
-
L
public static final int L
- See Also:
- Constant Field Values
-
M
public static final int M
- See Also:
- Constant Field Values
-
N
public static final int N
- See Also:
- Constant Field Values
-
O
public static final int O
- See Also:
- Constant Field Values
-
P
public static final int P
- See Also:
- Constant Field Values
-
Q
public static final int Q
- See Also:
- Constant Field Values
-
R
public static final int R
- See Also:
- Constant Field Values
-
patternConstants
protected final Constant[] patternConstants
-
patternInstructions
protected final Instruction[] patternInstructions
-
patternConstant
protected Constant patternConstant
-
matchingConstant
protected boolean matchingConstant
-
-
Constructor Detail
-
InstructionSequenceMatcher
public InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions)
Creates a new InstructionSequenceMatcher.- Parameters:
patternConstants- any constants referenced by the pattern instruction.patternInstructions- the pattern instruction sequence.
-
InstructionSequenceMatcher
public InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions, boolean matchSubclasses)
Creates a new InstructionSequenceMatcher.- Parameters:
patternConstants- any constants referenced by the pattern instruction.patternInstructions- the pattern instruction sequence.matchSubclasses- whether constant references on subclasses are matching when the pattern contains a constant of a superclass. (default: false)
-
-
Method Detail
-
reset
public void reset()
Starts matching from the first instruction again next time.
-
isMatching
public boolean isMatching()
Returns whether the complete pattern sequence has been matched.
-
instructionCount
public int instructionCount()
Returns the number of instructions in the pattern sequence.
-
matchedInstructionOffset
public int matchedInstructionOffset(int index)
Returns the matched instruction offset of the specified pattern instruction.
-
wasConstant
public boolean wasConstant(int argument)
Returns whether the specified wildcard argument was a constant from the constant pool in the most recent match.
-
matchedArgument
public int matchedArgument(int argument)
Returns the value of the specified matched argument (wildcard or not).
-
matchedArguments
public int[] matchedArguments(int[] arguments)
Returns the values of the specified matched arguments (wildcard or not).
-
matchedConstantIndex
public int matchedConstantIndex(int constantIndex)
Returns the index of the specified matched constant (wildcard or not).
-
matchedBranchOffset
public int matchedBranchOffset(int offset, int branchOffset)Returns the value of the specified matched branch offset (wildcard or not).
-
matchedJumpOffsets
public int[] matchedJumpOffsets(int offset, int[] jumpOffsets)Returns the values of the specified matched jump offsets (wildcard or not).
-
visitSimpleInstruction
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
- Specified by:
visitSimpleInstructionin interfaceInstructionVisitor
-
visitVariableInstruction
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
- Specified by:
visitVariableInstructionin interfaceInstructionVisitor
-
visitConstantInstruction
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
- Specified by:
visitConstantInstructionin interfaceInstructionVisitor
-
visitBranchInstruction
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
- Specified by:
visitBranchInstructionin interfaceInstructionVisitor
-
visitTableSwitchInstruction
public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction)
- Specified by:
visitTableSwitchInstructionin interfaceInstructionVisitor
-
visitLookUpSwitchInstruction
public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction)
- Specified by:
visitLookUpSwitchInstructionin interfaceInstructionVisitor
-
visitIntegerConstant
public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
- Specified by:
visitIntegerConstantin interfaceConstantVisitor
-
visitLongConstant
public void visitLongConstant(Clazz clazz, LongConstant longConstant)
- Specified by:
visitLongConstantin interfaceConstantVisitor
-
visitFloatConstant
public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
- Specified by:
visitFloatConstantin interfaceConstantVisitor
-
visitDoubleConstant
public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
- Specified by:
visitDoubleConstantin interfaceConstantVisitor
-
visitPrimitiveArrayConstant
public void visitPrimitiveArrayConstant(Clazz clazz, PrimitiveArrayConstant primitiveArrayConstant)
- Specified by:
visitPrimitiveArrayConstantin interfaceConstantVisitor
-
visitStringConstant
public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
- Specified by:
visitStringConstantin interfaceConstantVisitor
-
visitUtf8Constant
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
- Specified by:
visitUtf8Constantin interfaceConstantVisitor
-
visitDynamicConstant
public void visitDynamicConstant(Clazz clazz, DynamicConstant dynamicConstant)
- Specified by:
visitDynamicConstantin interfaceConstantVisitor
-
visitInvokeDynamicConstant
public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)
- Specified by:
visitInvokeDynamicConstantin interfaceConstantVisitor
-
visitMethodHandleConstant
public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
- Specified by:
visitMethodHandleConstantin interfaceConstantVisitor
-
visitAnyRefConstant
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
Description copied from interface:ConstantVisitorVisits any RefConstant instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyRefConstantin interfaceConstantVisitor
-
visitClassConstant
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- Specified by:
visitClassConstantin interfaceConstantVisitor
-
visitMethodTypeConstant
public void visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)
- Specified by:
visitMethodTypeConstantin interfaceConstantVisitor
-
visitNameAndTypeConstant
public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
- Specified by:
visitNameAndTypeConstantin interfaceConstantVisitor
-
matchingOpcodes
protected boolean matchingOpcodes(Instruction instruction1, Instruction instruction2)
-
matchingArguments
protected boolean matchingArguments(int argument1, int argument2)
-
matchingArguments
protected boolean matchingArguments(int[] arguments1, int[] arguments2)
-
matchingConstantIndices
protected boolean matchingConstantIndices(Clazz clazz, int constantIndex1, int constantIndex2)
-
matchingBranchOffsets
protected boolean matchingBranchOffsets(int offset, int branchOffset1, int branchOffset2)
-
matchingJumpOffsets
protected boolean matchingJumpOffsets(int offset, int[] jumpOffsets1, int[] jumpOffsets2)
-
finalMatch
protected boolean finalMatch(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction)
Performs a final check on the candidate sequence to match, after the pattern has been successfully fully matched with the sequence. Subclasses may override this method to implement additional constraints on the matched sequences.
-
main
public static void main(java.lang.String[] args)
Small sample application that illustrates the use of this class.
-
-