Java Code Examples for proguard.evaluation.value.Value#isParticular()

The following examples show how to use proguard.evaluation.value.Value#isParticular() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstantParameterFilter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    boolean isStatic =
        (programMethod.getAccessFlags() & AccessConstants.STATIC) != 0;

    int parameterStart = isStatic ? 0 : 1;
    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass),
                                               isStatic);

    for (int index = parameterStart; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 2
Source File: ConstantParameterFilter.java    From bazel with Apache License 2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 3
Source File: ConstantParameterFilter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 4
Source File: LoadingInvocationUnit.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    if (loadFieldValues)
    {
        // Do we know this field?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored field value.
            Value value = StoringInvocationUnit.getFieldValue((Field)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getFieldValue(clazz, refConstant, type);
}
 
Example 5
Source File: LoadingInvocationUnit.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
protected Value getMethodParameterValue(Clazz  clazz,
                                        Method method,
                                        int    parameterIndex,
                                        String type,
                                        Clazz  referencedClass)
{
    if (loadMethodParameterValues)
    {
        // Retrieve the stored method parameter value.
        Value value = StoringInvocationUnit.getMethodParameterValue(method, parameterIndex);
        if (value != null &&
            value.isParticular())
        {
            return value;
        }
    }

    return super.getMethodParameterValue(clazz,
                                         method,
                                         parameterIndex,
                                         type,
                                         referencedClass);
}
 
Example 6
Source File: LoadingInvocationUnit.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    if (loadMethodReturnValues)
    {
        // Do we know this method?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored method return value.
            Value value = StoringInvocationUnit.getMethodReturnValue((Method)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getMethodReturnValue(clazz,
                                      refConstant,
                                      type);
}
 
Example 7
Source File: ConstantParameterFilter.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 8
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the reference pushing instruction at the given offset by a
 * simpler push instruction, if possible.
 */
private void replaceReferencePushInstruction(Clazz       clazz,
                                             int         offset,
                                             Instruction instruction)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // A reference value can only be specific if it is null.
        replaceConstantPushInstruction(clazz,
                                       offset,
                                       instruction,
                                       InstructionConstants.OP_ACONST_NULL,
                                       0);
    }
}
 
Example 9
Source File: ConstantMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    Value value = StoringInvocationUnit.getMethodReturnValue(programMethod);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example 10
Source File: ConstantMemberFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    Value value = StoringInvocationUnit.getMethodReturnValue(programMethod);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example 11
Source File: ConstantMemberFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value value = StoringInvocationUnit.getFieldValue(programField);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramField(programClass, programField);
    }
}
 
Example 12
Source File: ConstantMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    Value value = StoringInvocationUnit.getMethodReturnValue(programMethod);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example 13
Source File: ConstantMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value value = StoringInvocationUnit.getFieldValue(programField);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramField(programClass, programField);
    }
}
 
Example 14
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the push instruction at the given offset by a simpler push
 * instruction, if possible.
 */
private void replaceAnyPushInstruction(Clazz       clazz,
                                       int         offset,
                                       Instruction instruction)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        switch (pushedValue.computationalType())
        {
            case Value.TYPE_INTEGER:
                replaceIntegerPushInstruction(clazz, offset, instruction);
                break;
            case Value.TYPE_LONG:
                replaceLongPushInstruction(clazz, offset, instruction);
                break;
            case Value.TYPE_FLOAT:
                replaceFloatPushInstruction(clazz, offset, instruction);
                break;
            case Value.TYPE_DOUBLE:
                replaceDoublePushInstruction(clazz, offset, instruction);
                break;
            case Value.TYPE_REFERENCE:
                replaceReferencePushInstruction(clazz, offset, instruction);
                break;
        }
    }
}
 
Example 15
Source File: ConstantMemberFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value value = StoringInvocationUnit.getFieldValue(programField);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramField(programClass, programField);
    }
}
 
Example 16
Source File: ConstantMemberFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value value = StoringInvocationUnit.getFieldValue(programField);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramField(programClass, programField);
    }
}
 
Example 17
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the double pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceDoublePushInstruction(Clazz       clazz,
                                          int         offset,
                                          Instruction instruction,
                                          int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Make sure to distinguish between +0.0 and -0.0.
        double value = pushedValue.doubleValue().value();
        if (value == 0.0 && Double.doubleToLongBits(value) == POS_ZERO_DOUBLE_BITS ||
            value == 1.0)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_DCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addDoubleConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_DLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 18
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the float pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceFloatPushInstruction(Clazz       clazz,
                                         int         offset,
                                         Instruction instruction,
                                         int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Make sure to distinguish between +0.0 and -0.0.
        float value = pushedValue.floatValue().value();
        if (value == 0.0f && Float.floatToIntBits(value) == POS_ZERO_FLOAT_BITS ||
            value == 1.0f ||
            value == 2.0f)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_FCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC,
                                        constantPoolEditor.addFloatConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_FLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 19
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the long pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceLongPushInstruction(Clazz       clazz,
                                        int         offset,
                                        Instruction instruction,
                                        int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        long value = pushedValue.longValue().value();
        if (value == 0L ||
            value == 1L)
        {
            replaceConstantPushInstruction(clazz,
                                   offset,
                                   instruction,
                                   InstructionConstants.OP_LCONST_0,
                                   (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addLongConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_LLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 20
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the integer pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceIntegerPushInstruction(Clazz       clazz,
                                           int         offset,
                                           Instruction instruction,
                                           int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        int value = pushedValue.integerValue().value();
        if (value << 16 >> 16 == value)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_SIPUSH,
                                           value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC,
                                        constantPoolEditor.addIntegerConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_ILOAD,
                                               variableIndex);
            }
        }
    }
}