instructionsequencematcher.java

来自「proguard 一个java的混淆器」· Java 代码 · 共 625 行 · 第 1/2 页

JAVA
625
字号
                   offset,                   lookUpSwitchInstruction);    }    // Implementations for ConstantVisitor.    public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)    {        IntegerConstant integerPatternConstant = (IntegerConstant)patternConstant;        // Compare the integer values.        matchingConstant = integerConstant.getValue() ==                           integerPatternConstant.getValue();    }    public void visitLongConstant(Clazz clazz, LongConstant longConstant)    {        LongConstant longPatternConstant = (LongConstant)patternConstant;        // Compare the long values.        matchingConstant = longConstant.getValue() ==                           longPatternConstant.getValue();    }    public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)    {        FloatConstant floatPatternConstant = (FloatConstant)patternConstant;        // Compare the float values.        matchingConstant = floatConstant.getValue() ==                           floatPatternConstant.getValue();    }    public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)    {        DoubleConstant doublePatternConstant = (DoubleConstant)patternConstant;        // Compare the double values.        matchingConstant = doubleConstant.getValue() ==                           doublePatternConstant.getValue();    }    public void visitStringConstant(Clazz clazz, StringConstant stringConstant)    {        StringConstant stringPatternConstant = (StringConstant)patternConstant;        // Check the UTF-8 constant.        matchingConstant =            matchingConstantIndices(clazz,                                    stringConstant.u2stringIndex,                                    stringPatternConstant.u2stringIndex);    }    public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)    {        Utf8Constant utf8PatternConstant = (Utf8Constant)patternConstant;        // Compare the actual strings.        matchingConstant = utf8Constant.getString().equals(                           utf8PatternConstant.getString());    }    public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)    {        RefConstant refPatternConstant = (RefConstant)patternConstant;        // Check the class and the name and type.        matchingConstant =            matchingConstantIndices(clazz,                                    refConstant.getClassIndex(),                                    refPatternConstant.getClassIndex()) &&            matchingConstantIndices(clazz,                                    refConstant.getNameAndTypeIndex(),                                    refPatternConstant.getNameAndTypeIndex());    }    public void visitClassConstant(Clazz clazz, ClassConstant classConstant)    {        ClassConstant classPatternConstant = (ClassConstant)patternConstant;        // Check the class name.        matchingConstant =            matchingConstantIndices(clazz,                                    classConstant.u2nameIndex,                                    classPatternConstant.u2nameIndex);    }    public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)    {        NameAndTypeConstant typePatternConstant = (NameAndTypeConstant)patternConstant;        // Check the name and the descriptor.        matchingConstant =            matchingConstantIndices(clazz,                                    nameAndTypeConstant.u2nameIndex,                                    typePatternConstant.u2nameIndex) &&            matchingConstantIndices(clazz,                                    nameAndTypeConstant.u2descriptorIndex,                                    typePatternConstant.u2descriptorIndex);    }    // Small utility methods.    private boolean matchingOpcodes(Instruction 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)    {        if (arguments1.length != arguments2.length)        {            return false;        }        for (int index = 0; index < arguments1.length; 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)    {        if (jumpOffsets1.length != jumpOffsets2.length)        {            return false;        }        for (int index = 0; index < jumpOffsets1.length; index++)        {            if (!matchingBranchOffsets(offset,                                       jumpOffsets1[index],                                       jumpOffsets2[index]))            {                return false;            }        }        return true;    }    private void checkMatch(boolean       condition,                            Clazz         clazz,                            Method        method,                            CodeAttribute codeAttribute,                            int           offset,                            Instruction   instruction)    {        if (DEBUG_MORE)        {            System.out.println("InstructionSequenceMatcher: ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"]: "+patternInstructions[patternInstructionIndex].toString(patternInstructionIndex)+(condition?"\t== ":"\t   ")+instruction.toString(offset));        }        // Did the instruction match?        if (condition)        {            // Remember the offset of the matching instruction.            matchedInstructionOffsets[patternInstructionIndex] = offset;            // Try to match the next instruction next time.            patternInstructionIndex++;            // Did we match all instructions in the sequence?            matching = patternInstructionIndex == patternInstructions.length;            if (matching)            {                if (DEBUG)                {                    System.out.println("InstructionSequenceMatcher: ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"]");                    for (int index = 0; index < patternInstructionIndex; index++)                    {                        System.out.println("    "+InstructionFactory.create(codeAttribute.code, matchedInstructionOffsets[index]).toString(matchedInstructionOffsets[index]));                    }                }                // Start matching from the first instruction again next time.                reset();            }        }        else        {            // The instruction didn't match.            matching = false;            // Is this a failed second instruction?            boolean retry = patternInstructionIndex == 1;            // Start matching from the first instruction next time.            reset();            // Retry a failed second instruction as a first instruction.            if (retry)            {                instruction.accept(clazz, method, codeAttribute, offset, this);            }        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?