类 InstructionSequenceReplacer
java.lang.Object
proguard.classfile.editor.InstructionSequenceReplacer
- 所有已实现的接口:
ConstantVisitor,InstructionVisitor
public class InstructionSequenceReplacer
extends Object
implements InstructionVisitor, ConstantVisitor
This
InstructionVisitor replaces a given pattern instruction sequence by another given
replacement instruction sequence. The arguments of the instruction sequences can be wildcards
that are matched and replaced.
The class also supports labels (label()) and exception handlers (catch_(int,int,int)) in replacement sequences. They provide local branch offsets inside the
replacement sequences (InstructionSequenceReplacer.Label.offset()). For example, creating a replacement sequence with
the help of InstructionSequenceBuilder:
final InstructionSequenceReplacer.Label TRY_START = InstructionSequenceReplacer.label();
final InstructionSequenceReplacer.Label TRY_END = InstructionSequenceReplacer.label();
final InstructionSequenceReplacer.Label CATCH_END = InstructionSequenceReplacer.label();
final InstructionSequenceReplacer.Label CATCH_EXCEPTION =
InstructionSequenceReplacer.catch_(TRY_START.offset(),
TRY_END.offset(),
constantPoolEditor.addClassConstant("java/lang/Exception", null));
Instructions[] replacementInstructions = builder
.label(TRY_START)
......
.label(TRY_END)
.goto_(CATCH_END.offset())
.catch_(CATCH_EXCEPTION)
......
.athrow()
.label(CATCH_END)
......
.instructions();
-
嵌套类概要
嵌套类修饰符和类型类说明static classThis pseudo-instruction represents a label that marks an instruction offset, for use in the context of the sequence replacer only. -
字段概要
字段修饰符和类型字段说明static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
构造器概要
构造器限定符构造器说明InstructionSequenceReplacer(Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor) Creates a new InstructionSequenceReplacer.InstructionSequenceReplacer(Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) Creates a new InstructionSequenceReplacer.InstructionSequenceReplacer(InstructionSequenceMatcher instructionSequenceMatcher, Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) 已过时。protectedInstructionSequenceReplacer(InstructionSequenceMatcher instructionSequenceMatcher, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) Creates a new InstructionSequenceReplacer. -
方法概要
修饰符和类型方法说明catch_(int startOffset, int endOffset, int catchType) Creates a new catch instance that can be used as a pseudo-instruction to mark the start of an exception handler.protected InstructionSequenceMatcherlabel()Creates a new label that can be used as a pseudo-instruction to mark a local offset.protected intmatchedArgument(int argument) protected intmatchedArgument(Clazz clazz, int argument) Returns the matched argument for the given pattern argument.protected intmatchedArgument(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int argument) Returns the matched argument for the given pattern argument.protected intmatchedBranchOffset(int offset, int branchOffset) Returns the value of the specified matched branch offset.protected ConstantmatchedConstant(ProgramClass programClass, int argument) protected intmatchedConstantIndex(ProgramClass programClass, int constantIndex) 已过时。protected intmatchedConstantIndex(ProgramClass programClass, ProgramMethod programMethod, int constantIndex) Returns the matched or newly created constant index for the given pattern constant index.protected int[]matchedJumpOffsets(int offset, int[] jumpOffsets) Returns the values of the specified matched jump offsets.voidvisitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) Visits any Instruction instance.protected booleanwasConstant(int argument) 从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 proguard.classfile.constant.visitor.ConstantVisitor
visitAnyConstant, visitAnyMethodrefConstant, visitAnyRefConstant, visitClassConstant, visitDoubleConstant, visitDynamicConstant, visitFieldrefConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitInvokeDynamicConstant, visitLongConstant, visitMethodHandleConstant, visitMethodrefConstant, visitMethodTypeConstant, visitModuleConstant, visitNameAndTypeConstant, visitPackageConstant, visitPrimitiveArrayConstant, visitStringConstant, visitUtf8Constant从接口继承的方法 proguard.classfile.instruction.visitor.InstructionVisitor
visitAnySwitchInstruction, visitBranchInstruction, visitConstantInstruction, visitLookUpSwitchInstruction, visitSimpleInstruction, visitTableSwitchInstruction, visitVariableInstruction
-
字段详细资料
-
X
public static final int X- 另请参阅:
-
Y
public static final int Y- 另请参阅:
-
Z
public static final int Z- 另请参阅:
-
A
public static final int A- 另请参阅:
-
B
public static final int B- 另请参阅:
-
C
public static final int C- 另请参阅:
-
D
public static final int D- 另请参阅:
-
E
public static final int E- 另请参阅:
-
F
public static final int F- 另请参阅:
-
G
public static final int G- 另请参阅:
-
H
public static final int H- 另请参阅:
-
I
public static final int I- 另请参阅:
-
J
public static final int J- 另请参阅:
-
K
public static final int K- 另请参阅:
-
L
public static final int L- 另请参阅:
-
M
public static final int M- 另请参阅:
-
N
public static final int N- 另请参阅:
-
O
public static final int O- 另请参阅:
-
P
public static final int P- 另请参阅:
-
Q
public static final int Q- 另请参阅:
-
R
public static final int R- 另请参阅:
-
STRING_A_LENGTH
public static final int STRING_A_LENGTH- 另请参阅:
-
CLASS_A_NAME
public static final int CLASS_A_NAME- 另请参阅:
-
CLASS_A_SIMPLE_NAME
public static final int CLASS_A_SIMPLE_NAME- 另请参阅:
-
BOOLEAN_A_STRING
public static final int BOOLEAN_A_STRING- 另请参阅:
-
CHAR_A_STRING
public static final int CHAR_A_STRING- 另请参阅:
-
INT_A_STRING
public static final int INT_A_STRING- 另请参阅:
-
LONG_A_STRING
public static final int LONG_A_STRING- 另请参阅:
-
FLOAT_A_STRING
public static final int FLOAT_A_STRING- 另请参阅:
-
DOUBLE_A_STRING
public static final int DOUBLE_A_STRING- 另请参阅:
-
STRING_A_STRING
public static final int STRING_A_STRING- 另请参阅:
-
BOOLEAN_B_STRING
public static final int BOOLEAN_B_STRING- 另请参阅:
-
CHAR_B_STRING
public static final int CHAR_B_STRING- 另请参阅:
-
INT_B_STRING
public static final int INT_B_STRING- 另请参阅:
-
LONG_B_STRING
public static final int LONG_B_STRING- 另请参阅:
-
FLOAT_B_STRING
public static final int FLOAT_B_STRING- 另请参阅:
-
DOUBLE_B_STRING
public static final int DOUBLE_B_STRING- 另请参阅:
-
STRING_B_STRING
public static final int STRING_B_STRING- 另请参阅:
-
-
构造器详细资料
-
InstructionSequenceReplacer
public InstructionSequenceReplacer(Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor) Creates a new InstructionSequenceReplacer.- 参数:
patternConstants- any constants referenced by the pattern instructions.patternInstructions- the pattern instruction sequence.replacementConstants- any constants referenced by the replacement instructions.replacementInstructions- the replacement instruction sequence.branchTargetFinder- a branch target finder that has been initialized to indicate branch targets in the visited code.codeAttributeEditor- a code editor that can be used for accumulating changes to the code.
-
InstructionSequenceReplacer
public InstructionSequenceReplacer(Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) Creates a new InstructionSequenceReplacer.- 参数:
patternConstants- any constants referenced by the pattern instructions.patternInstructions- the pattern instruction sequence.replacementConstants- any constants referenced by the replacement instructions.replacementInstructions- the replacement instruction sequence.branchTargetFinder- a branch target finder that has been initialized to indicate branch targets in the visited code.codeAttributeEditor- a code editor that can be used for accumulating changes to the code.extraInstructionVisitor- an optional extra visitor for all deleted load instructions.
-
InstructionSequenceReplacer
@Deprecated public InstructionSequenceReplacer(InstructionSequenceMatcher instructionSequenceMatcher, Constant[] patternConstants, Instruction[] patternInstructions, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) 已过时。Creates a new InstructionSequenceReplacer.- 参数:
instructionSequenceMatcher- a suitable instruction sequence matcher.patternConstants- any constants referenced by the pattern instructions.patternInstructions- the pattern instruction sequence.replacementConstants- any constants referenced by the replacement instructions.replacementInstructions- the replacement instruction sequence.branchTargetFinder- a branch target finder that has been initialized to indicate branch targets in the visited code.codeAttributeEditor- a code editor that can be used for accumulating changes to the code.extraInstructionVisitor- an optional extra visitor for all deleted load instructions.
-
InstructionSequenceReplacer
protected InstructionSequenceReplacer(InstructionSequenceMatcher instructionSequenceMatcher, Constant[] replacementConstants, Instruction[] replacementInstructions, BranchTargetFinder branchTargetFinder, CodeAttributeEditor codeAttributeEditor, InstructionVisitor extraInstructionVisitor) Creates a new InstructionSequenceReplacer.- 参数:
instructionSequenceMatcher- a suitable instruction sequence matcher.replacementConstants- any constants referenced by the replacement instructions.replacementInstructions- the replacement instruction sequence.branchTargetFinder- a branch target finder that has been initialized to indicate branch targets in the visited code.codeAttributeEditor- a code editor that can be used for accumulating changes to the code.extraInstructionVisitor- an optional extra visitor for all deleted load instructions.
-
-
方法详细资料
-
visitAnyInstruction
public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) 从接口复制的说明:InstructionVisitorVisits any Instruction instance. The more specific default implementations of this interface delegate to this method.- 指定者:
visitAnyInstruction在接口中InstructionVisitor
-
matchedArgument
protected int matchedArgument(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int argument) Returns the matched argument for the given pattern argument. -
matchedArgument
Returns the matched argument for the given pattern argument. -
matchedConstantIndex
已过时。 -
matchedConstantIndex
protected int matchedConstantIndex(ProgramClass programClass, ProgramMethod programMethod, int constantIndex) Returns the matched or newly created constant index for the given pattern constant index. -
matchedBranchOffset
protected int matchedBranchOffset(int offset, int branchOffset) Returns the value of the specified matched branch offset. -
matchedJumpOffsets
protected int[] matchedJumpOffsets(int offset, int[] jumpOffsets) Returns the values of the specified matched jump offsets. -
getInstructionSequenceMatcher
-
wasConstant
protected boolean wasConstant(int argument) -
matchedConstant
-
matchedArgument
protected int matchedArgument(int argument) -
label
Creates a new label that can be used as a pseudo-instruction to mark a local offset. Its offset can be used as a branch target in replacement instructions (InstructionSequenceReplacer.Label.offset()). -
catch_
public static InstructionSequenceReplacer.Label catch_(int startOffset, int endOffset, int catchType) Creates a new catch instance that can be used as a pseudo-instruction to mark the start of an exception handler. Its offset can be used as a branch target in replacement instructions (InstructionSequenceReplacer.Label.offset()).
-
InstructionSequenceReplacer(InstructionSequenceMatcher, Constant[], Instruction[], BranchTargetFinder, CodeAttributeEditor, InstructionVisitor)instead.