📄 instructionsequencereplacer.java
字号:
} public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) { Instruction patternInstruction = patternInstructions[patternInstructionIndex]; // Check if the instruction matches the next instruction in the from // sequence. boolean condition = acceptableOffset(offset) && matchingOpcodes(lookUpSwitchInstruction, patternInstruction) && matchingArguments(lookUpSwitchInstruction.defaultOffset, ((LookUpSwitchInstruction)patternInstruction).defaultOffset) && matchingArguments(lookUpSwitchInstruction.jumpOffsetCount, ((LookUpSwitchInstruction)patternInstruction).jumpOffsetCount) && matchingArguments(lookUpSwitchInstruction.cases, ((LookUpSwitchInstruction)patternInstruction).cases, lookUpSwitchInstruction.jumpOffsetCount) && matchingJumpOffsets(offset, lookUpSwitchInstruction.jumpOffsets, ((LookUpSwitchInstruction)patternInstruction).jumpOffsets, lookUpSwitchInstruction.jumpOffsetCount); // Act on it. matchInstruction(condition, clazz, method, codeAttribute, offset, lookUpSwitchInstruction); } // Implementations for ConstantVisitor. public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant) { matchingConstant = integerConstant.getValue() == ((IntegerConstant)patternConstant).getValue(); } public void visitLongConstant(Clazz clazz, LongConstant longConstant) { matchingConstant = longConstant.getValue() == ((LongConstant)patternConstant).getValue(); } public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant) { matchingConstant = floatConstant.getValue() == ((FloatConstant)patternConstant).getValue(); } public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant) { matchingConstant = doubleConstant.getValue() == ((DoubleConstant)patternConstant).getValue(); } public void visitStringConstant(Clazz clazz, StringConstant stringConstant) { // Check the UTF-8 constant. matchingConstant = matchingConstantIndices(clazz, stringConstant.u2stringIndex, ((StringConstant)patternConstant).u2stringIndex); } public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { matchingConstant = utf8Constant.getString().equals( ((Utf8Constant)patternConstant).getString()); } public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant) { // Check the class and the name and type. matchingConstant = matchingConstantIndices(clazz, refConstant.getClassIndex(), ((RefConstant)patternConstant).getClassIndex()) && matchingConstantIndices(clazz, refConstant.getNameAndTypeIndex(), ((RefConstant)patternConstant).getNameAndTypeIndex()); } public void visitClassConstant(Clazz clazz, ClassConstant classConstant) { // Check the class name. matchingConstant = matchingConstantIndices(clazz, classConstant.u2nameIndex, ((ClassConstant)patternConstant).u2nameIndex); } public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) { // Check the name and the descriptor. matchingConstant = matchingConstantIndices(clazz, nameAndTypeConstant.u2nameIndex, ((NameAndTypeConstant)patternConstant).u2nameIndex) && matchingConstantIndices(clazz, nameAndTypeConstant.u2descriptorIndex, ((NameAndTypeConstant)patternConstant).u2descriptorIndex); } // Small utility methods. private boolean acceptableOffset(int offset) { // Check the offset. return patternInstructionIndex == 0 || !branchTargetFinder.isTarget(offset); } private boolean matchingOpcodes(Instruction instruction1, Instruction instruction2) { // Check the opcode. return instruction1.opcode == instruction2.opcode; } private boolean matchingOpcodes(SimpleInstruction instruction1, Instruction instruction2) { // Check the opcode. return instruction1.opcode == instruction2.opcode || instruction1.canonicalOpcode() == instruction2.opcode; } private boolean matchingOpcodes(VariableInstruction instruction1, Instruction instruction2) { // Check the opcode. return instruction1.opcode == instruction2.opcode || instruction1.canonicalOpcode() == instruction2.opcode; } private boolean matchingArguments(int argument1, int argument2) { int argumentIndex = argument2 - X; if (argumentIndex < 0) { // Check the literal argument. return argument1 == argument2; } else if ((matchedArgumentFlags & (1 << argumentIndex)) == 0) { // Store a wildcard argument. matchedArguments[argumentIndex] = argument1; matchedArgumentFlags |= 1 << argumentIndex; return true; } else { // Check the previously stored wildcard argument. return matchedArguments[argumentIndex] == argument1; } } private boolean matchingArguments(int[] arguments1, int[] arguments2, int argumentCount) { for (int index = 0; index < argumentCount; index++) { if (!matchingArguments(arguments1[index], arguments2[index])) { return false; } } return true; } private boolean matchingConstantIndices(Clazz clazz, int constantIndex1, int constantIndex2) { if (constantIndex2 >= X) { // Check the constant index. return matchingArguments(constantIndex1, constantIndex2); } else if ((matchedConstantFlags & (1 << constantIndex2)) == 0) { // Check the actual constant. matchingConstant = false; patternConstant = patternConstants[constantIndex2]; if (clazz.getTag(constantIndex1) == patternConstant.getTag()) { clazz.constantPoolEntryAccept(constantIndex1, this); if (matchingConstant) { // Store the constant index. matchedConstantIndices[constantIndex2] = constantIndex1; matchedConstantFlags |= 1 << constantIndex2; } } return matchingConstant; } else { // Check a previously stored constant index. return matchedConstantIndices[constantIndex2] == constantIndex1; } } private boolean matchingBranchOffsets(int offset, int branchOffset1, int branchOffset2) { int argumentIndex = branchOffset2 - X; if (argumentIndex < 0) { // Check the literal argument. return branchOffset1 == branchOffset2; } else if ((matchedArgumentFlags & (1 << argumentIndex)) == 0) { // Store a wildcard argument. matchedArguments[argumentIndex] = offset + branchOffset1; matchedArgumentFlags |= 1 << argumentIndex; return true; } else { // Check the previously stored wildcard argument. return matchedArguments[argumentIndex] == offset + branchOffset1; } } private boolean matchingJumpOffsets(int offset, int[] jumpOffsets1, int[] jumpOffsets2, int jumpOffsetCount) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -