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

The following examples show how to use proguard.evaluation.value.Value#computationalType() . These examples are extracted from open source projects. 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
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 2
/**
 * Returns whether the specified variable is initialized at the specified
 * offset.
 */
private boolean isVariableInitialization(int instructionOffset,
                                         int variableIndex)
{
    // Wasn't the variable set yet?
    Value valueBefore = partialEvaluator.getVariablesBefore(instructionOffset).getValue(variableIndex);
    if (valueBefore == null)
    {
        return true;
    }

    // Is the computational type different now?
    Value valueAfter = partialEvaluator.getVariablesAfter(instructionOffset).getValue(variableIndex);
    if (valueAfter.computationalType() != valueBefore.computationalType())
    {
        return true;
    }

    // Was the producer an argument (which may be removed)?
    Value producersBefore = partialEvaluator.getVariablesBefore(instructionOffset).getProducerValue(variableIndex);
    return producersBefore.instructionOffsetValue().instructionOffsetCount() == 1 &&
           producersBefore.instructionOffsetValue().instructionOffset(0) == PartialEvaluator.AT_METHOD_ENTRY;
}
 
Example 3
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 4
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 5
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 6
public boolean equals(Object object)
{
    if (object == null ||
        this.getClass() != object.getClass())
    {
        return false;
    }

    Variables other = (Variables)object;

    if (this.size != other.size)
    {
        return false;
    }

    for (int index = 0; index < size; index++)
    {
        Value thisValue  = this.values[index];
        Value otherValue = other.values[index];

        // Occasionally, two values of different types might be
        // present in the same variable in a variable frame
        // (corresponding to two local variables that share the
        // same index), at some point outside of their scopes.
        // We'll ignore these.
        if (thisValue  != null &&
            otherValue != null &&
            thisValue.computationalType() == otherValue.computationalType() &&
            !thisValue.equals(otherValue))
        {
            return false;
        }
    }

    return true;
}
 
Example 7
/**
 * 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 8
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);

    int classIndex = 0;

    // Go over the parameters.
    for (int parameterIndex = parameterStart; parameterIndex < parameterCount; parameterIndex++)
    {
        Value parameterValue = StoringInvocationUnit.getMethodParameterValue(programMethod, parameterIndex);
         if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
         {
             Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
             if (programMethod.referencedClasses[classIndex] != referencedClass)
             {
                 if (DEBUG)
                 {
                     System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programMethod.getName(programClass)+programMethod.getDescriptor(programClass));
                     System.out.println("  "+programMethod.referencedClasses[classIndex].getName()+" -> "+referencedClass.getName());
                 }

                 programMethod.referencedClasses[classIndex] = referencedClass;

                 // Visit the method, if required.
                 if (extraParameterMemberVisitor != null)
                 {
                     extraParameterMemberVisitor.visitProgramMethod(programClass, programMethod);
                 }
             }

             classIndex++;
         }
    }
}
 
Example 9
/**
 * Creates and returns the verification type corresponding to the given
 * value. If necessary, a class constant is added to the constant pool of
 * the given class.
 */
private VerificationType correspondingVerificationType(ProgramClass  programClass,
                                                       ProgramMethod programMethod,
                                                       CodeAttribute codeAttribute,
                                                       int           offset,
                                                       boolean       isVariable0,
                                                       Value value,
                                                       Value producerValue)
{
    if (value == null)
    {
        return VerificationTypeFactory.createTopType();
    }

    int type = value.computationalType();

    switch (type)
    {
        case Value.TYPE_INSTRUCTION_OFFSET:
        case Value.TYPE_INTEGER:   return VerificationTypeFactory.createIntegerType();
        case Value.TYPE_LONG:      return VerificationTypeFactory.createLongType();
        case Value.TYPE_FLOAT:     return VerificationTypeFactory.createFloatType();
        case Value.TYPE_DOUBLE:    return VerificationTypeFactory.createDoubleType();
        case Value.TYPE_TOP:       return VerificationTypeFactory.createTopType();
        case Value.TYPE_REFERENCE:
            // Is it a Null type?
            ReferenceValue referenceValue = value.referenceValue();
            if (referenceValue.isNull() == Value.ALWAYS)
            {
                return VerificationTypeFactory.createNullType();
            }

            // Does the reference type have a single producer?
            if (offset != PartialEvaluator.AT_METHOD_ENTRY)
            {
                InstructionOffsetValue producers = producerValue.instructionOffsetValue();
                if (producers.instructionOffsetCount() == 1)
                {
                    int producerOffset = producers.instructionOffset(0);

                    // Follow any dup or swap instructions.
                    while (producerOffset != PartialEvaluator.AT_METHOD_ENTRY &&
                           isDupOrSwap(codeAttribute.code[producerOffset]))
                    {
                        producers      = partialEvaluator.getStackBefore(producerOffset).getTopProducerValue(0).instructionOffsetValue();
                        producerOffset = producers.instructionOffset(0);
                    }

                    // Are we in an instance initialization method,
                    // before the super initialization, loading "this"?
                    if (partialEvaluator.isInitializer()                       &&
                        offset <= partialEvaluator.superInitializationOffset() &&
                        (isVariable0 ||
                         producerOffset > PartialEvaluator.AT_METHOD_ENTRY &&
                         codeAttribute.code[producerOffset] == InstructionConstants.OP_ALOAD_0))
                    {
                        // It's an UninitializedThis type.
                        return VerificationTypeFactory.createUninitializedThisType();
                    }

                    // Is the reference type newly created and still
                    // uninitialized?
                    if (producerOffset > PartialEvaluator.AT_METHOD_ENTRY &&
                        offset <= partialEvaluator.initializationOffset(producerOffset))
                    {
                        // It's an Uninitialized type.
                        return VerificationTypeFactory.createUninitializedType(producerOffset);
                    }
                }
            }

            // It's an ordinary Object type.
            return VerificationTypeFactory.createObjectType(createClassConstant(programClass, referenceValue));
    }

    throw new IllegalArgumentException("Unknown computational type ["+type+"]");
}
 
Example 10
/**
 * Generalizes the values of this Variables object with the values of the
 * given Variables object.
 * @param clearConflictingOtherVariables specifies whether the other
 *                                       variables should be cleared too,
 *                                       in case of conflicts.
 * @return whether the generalization has made any difference.
 */
public boolean generalize(Variables other,
                          boolean   clearConflictingOtherVariables)
{
    if (this.size != other.size)
    {
        throw new IllegalArgumentException("Variable frames have different sizes ["+this.size+"] and ["+other.size+"]");
    }

    boolean changed = false;

    for (int index = 0; index < size; index++)
    {
        Value thisValue  = this.values[index];
        Value otherValue = other.values[index];

        // Occasionally, two values of different types might be present
        // in the same variable in a variable frame (corresponding to
        // two local variables that share the same index), at some point
        // outside of their scopes. Don't generalize the variable then,
        // but let it clear instead.
        if (thisValue  != null &&
            otherValue != null &&
            thisValue.computationalType() == otherValue.computationalType())
        {
            Value newValue = thisValue.generalize(otherValue);

            changed = changed || !thisValue.equals(newValue);

            this.values[index] = newValue;
        }
        else
        {
            changed = changed || thisValue != null;

            this.values[index] = null;

            if (clearConflictingOtherVariables)
            {
                other.values[index] = null;
            }
        }
    }

    return changed;
}
 
Example 11
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));

    int classIndex = 0;

    // Go over the parameters.
    for (int parameterIndex = firstParameterIndex; parameterIndex < parameterCount; parameterIndex++)
    {
        Value parameterValue = StoringInvocationUnit.getMethodParameterValue(programMethod, parameterIndex);
         if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
         {
             Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
             if (programMethod.referencedClasses[classIndex] != referencedClass)
             {
                 if (DEBUG)
                 {
                     System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programMethod.getName(programClass)+programMethod.getDescriptor(programClass));
                     System.out.println("  "+programMethod.referencedClasses[classIndex].getName()+" -> "+referencedClass.getName());
                 }

                 programMethod.referencedClasses[classIndex] = referencedClass;

                 // Visit the method, if required.
                 if (extraParameterMemberVisitor != null)
                 {
                     extraParameterMemberVisitor.visitProgramMethod(programClass, programMethod);
                 }
             }

             classIndex++;
         }
    }
}
 
Example 12
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));

    int classIndex = 0;

    // Go over the parameters.
    for (int parameterIndex = firstParameterIndex; parameterIndex < parameterCount; parameterIndex++)
    {
        Value parameterValue = StoringInvocationUnit.getMethodParameterValue(programMethod, parameterIndex);
         if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
         {
             Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
             if (programMethod.referencedClasses[classIndex] != referencedClass)
             {
                 if (DEBUG)
                 {
                     System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programMethod.getName(programClass)+programMethod.getDescriptor(programClass));
                     System.out.println("  "+programMethod.referencedClasses[classIndex].getName()+" -> "+referencedClass.getName());
                 }

                 programMethod.referencedClasses[classIndex] = referencedClass;

                 // Visit the method, if required.
                 if (extraParameterMemberVisitor != null)
                 {
                     extraParameterMemberVisitor.visitProgramMethod(programClass, programMethod);
                 }
             }

             classIndex++;
         }
    }
}
 
Example 13
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));

    int classIndex = 0;

    // Go over the parameters.
    for (int parameterIndex = firstParameterIndex; parameterIndex < parameterCount; parameterIndex++)
    {
        Value parameterValue = StoringInvocationUnit.getMethodParameterValue(programMethod, parameterIndex);
         if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
         {
             Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
             if (programMethod.referencedClasses[classIndex] != referencedClass)
             {
                 if (DEBUG)
                 {
                     System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programMethod.getName(programClass)+programMethod.getDescriptor(programClass));
                     System.out.println("  "+programMethod.referencedClasses[classIndex].getName()+" -> "+referencedClass.getName());
                 }

                 programMethod.referencedClasses[classIndex] = referencedClass;

                 // Visit the method, if required.
                 if (extraParameterMemberVisitor != null)
                 {
                     extraParameterMemberVisitor.visitProgramMethod(programClass, programMethod);
                 }
             }

             classIndex++;
         }
    }
}