proguard.classfile.constant.ClassConstant Java Examples

The following examples show how to use proguard.classfile.constant.ClassConstant. 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: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Do we know the referenced class?
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass != null)
    {
        // Has the class name changed?
        String className    = classConstant.getName(clazz);
        String newClassName = newClassName(className, referencedClass);
        if (!className.equals(newClassName))
        {
            // Refer to a new Utf8 entry.
            classConstant.u2nameIndex =
                new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newClassName);
        }
    }
}
 
Example #2
Source File: LibraryClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private Constant createConstant()
{
    int u1tag = dataInput.readUnsignedByte();

    switch (u1tag)
    {
        case ClassConstants.CONSTANT_Utf8:               return new Utf8Constant();
        case ClassConstants.CONSTANT_Integer:            return new IntegerConstant();
        case ClassConstants.CONSTANT_Float:              return new FloatConstant();
        case ClassConstants.CONSTANT_Long:               return new LongConstant();
        case ClassConstants.CONSTANT_Double:             return new DoubleConstant();
        case ClassConstants.CONSTANT_String:             return new StringConstant();
        case ClassConstants.CONSTANT_Fieldref:           return new FieldrefConstant();
        case ClassConstants.CONSTANT_Methodref:          return new MethodrefConstant();
        case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant();
        case ClassConstants.CONSTANT_Class:              return new ClassConstant();
        case ClassConstants.CONSTANT_NameAndType:        return new NameAndTypeConstant();

        default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool");
    }
}
 
Example #3
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Check if this class entry is an array type.
    if (ClassUtil.isInternalArrayType(classConstant.getName(clazz)))
    {
        isInterfaceMethod = false;
    }
    else
    {
        // Check if this class entry refers to an interface class.
        Clazz referencedClass = classConstant.referencedClass;
        if (referencedClass != null)
        {
            isInterfaceMethod = (referencedClass.getAccessFlags() & ClassConstants.INTERNAL_ACC_INTERFACE) != 0;
        }
    }
}
 
Example #4
Source File: ClassRenamer.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Update the Class entry if required.
    String name    = clazz.getName();
    String newName = ClassObfuscator.newClassName(clazz);
    if (newName != null && !newName.equals(name))
    {
        // Refer to a new Utf8 entry.
        classConstant.u2nameIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newName);

        if (extraClassVisitor != null)
        {
            clazz.accept(extraClassVisitor);
        }
    }
}
 
Example #5
Source File: DynamicClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Prints out a note about the class cast to this class, if applicable.
 */
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Print out a note about the class cast.
    if (noteExceptionMatcher == null ||
        !noteExceptionMatcher.matches(classConstant.getName(clazz)))
    {
        notePrinter.print(clazz.getName(),
                          classConstant.getName(clazz),
                          "Note: " +
                          ClassUtil.externalClassName(clazz.getName()) +
                          " calls '(" +
                          ClassUtil.externalClassName(classConstant.getName(clazz)) +
                          ")Class.forName(variable).newInstance()'");
    }
}
 
Example #6
Source File: TargetClassChanger.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Explicitly adds a new class constant for the given class in the given
 * program class.
 */
private int addNewClassConstant(ProgramClass programClass,
                                String       className,
                                Clazz        referencedClass)
{
    ConstantPoolEditor constantPoolEditor =
        new ConstantPoolEditor(programClass);

    int nameIndex =
        constantPoolEditor.addUtf8Constant(className);

    int classConstantIndex =
        constantPoolEditor.addConstant(new ClassConstant(nameIndex,
                                                         referencedClass));
    return classConstantIndex;
}
 
Example #7
Source File: InterfaceUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    boolean classUsed = usageMarker.isUsed(classConstant);

    if (!classUsed)
    {
        // The ClassConstant isn't marked as being used yet. But maybe it
        // should be included as an interface, so check the actual class.
        classConstant.referencedClassAccept(this);
        classUsed = used;

        if (classUsed)
        {
            // The class is being used. Mark the ClassConstant as being used
            // as well.
            usageMarker.markAsUsed(classConstant);

            clazz.constantPoolEntryAccept(classConstant.u2nameIndex, this);
        }
    }

    // The return values.
    used    =  classUsed;
    anyUsed |= classUsed;
}
 
Example #8
Source File: InnerUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    classUsed = usageMarker.isUsed(classConstant);

    // Is the class constant marked as being used?
    if (!classUsed)
    {
        // Check the referenced class.
        classUsed = true;
        classConstant.referencedClassAccept(this);

        // Is the referenced class marked as being used?
        if (classUsed)
        {
            // Mark the class constant and its Utf8 constant.
            usageMarker.markAsUsed(classConstant);

            markConstant(clazz, classConstant.u2nameIndex);
        }
    }
}
 
Example #9
Source File: AnnotationUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    classUsed = usageMarker.isUsed(classConstant);

    // Is the class constant marked as being used?
    if (!classUsed)
    {
        // Check the referenced class.
        classUsed = true;
        classConstant.referencedClassAccept(this);

        // Is the referenced class marked as being used?
        if (classUsed)
        {
            // Mark the class constant and its Utf8 constant.
            usageMarker.markAsUsed(classConstant);

            markConstant(clazz, classConstant.u2nameIndex);
        }
    }
}
 
Example #10
Source File: ConstantAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add the class constant, with its referenced class..
    constantIndex =
        constantPoolEditor.addClassConstant(classConstant.getName(clazz),
                                            classConstant.referencedClass);
}
 
Example #11
Source File: ConstantPoolEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Finds or creates a ClassConstant constant pool entry with the given name.
 * @return the constant pool index of the ClassConstant.
 */
public int addClassConstant(String name,
                            Clazz  referencedClass)
{
    int        constantPoolCount = targetClass.u2constantPoolCount;
    Constant[] constantPool      = targetClass.constantPool;

    // Check if the entry already exists.
    for (int index = 1; index < constantPoolCount; index++)
    {
        Constant constant = constantPool[index];

        if (constant != null &&
            constant.getTag() == ClassConstants.CONSTANT_Class)
        {
            ClassConstant classConstant = (ClassConstant)constant;
            if (classConstant.getName(targetClass).equals(name))
            {
                return index;
            }
        }
    }

    int nameIndex = addUtf8Constant(name);

    return addConstant(new ClassConstant(nameIndex, referencedClass));
}
 
Example #12
Source File: PackageVisibleMemberInvokingClassMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Check the referenced class.
    if (classConstant.referencedClass != clazz)
    {
        referencingClass = clazz;

        classConstant.referencedClassAccept(this);
    }
}
 
Example #13
Source File: ExceptionAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add a class constant to the constant pool.
    constantAdder.visitClassConstant(clazz, classConstant);

    // Add the index of the class constant to the list of exceptions.
    exceptionsAttributeEditor.addException(constantAdder.getConstantIndex());
}
 
Example #14
Source File: InstructionSequenceMatcher.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    ClassConstant classPatternConstant = (ClassConstant)patternConstant;

    // Check the class name.
    matchingConstant =
        matchingConstantIndices(clazz,
                                classConstant.u2nameIndex,
                                classPatternConstant.u2nameIndex);
}
 
Example #15
Source File: DynamicMemberReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Remembers the referenced class.
 */
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (DEBUG)
    {
        System.out.println("DynamicMemberReferenceInitializer: ["+clazz.getName()+"] matched class ["+classConstant.getName(clazz)+"]");
    }

    // Remember the referenced class.
    referencedClass = ClassUtil.isInternalArrayType(classConstant.getName(clazz)) ?
        null :
        classConstant.referencedClass;
}
 
Example #16
Source File: StringSharer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass != null)
    {
        // Put the actual class's name string in the class pool.
        name = referencedClass.getName();
        clazz.constantPoolEntryAccept(classConstant.u2nameIndex, this);
    }
}
 
Example #17
Source File: ExceptClassConstantFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (!classConstant.getName(clazz).equals(exceptClassName))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #18
Source File: ImplementedClassConstantFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !referencedClass.extendsOrImplements(implementedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #19
Source File: AccessFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    referencingClass = clazz;

    // Make sure the access flags of the referenced class are acceptable.
    classConstant.referencedClassAccept(this);
}
 
Example #20
Source File: LibraryClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the class name of the ClassConstant at the specified index in the
 * reusable constant pool.
 */
private String getClassName(int constantIndex)
{
    ClassConstant classEntry = (ClassConstant)constantPool[constantIndex];

    return getString(classEntry.u2nameIndex);
}
 
Example #21
Source File: ImplementingClassConstantFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !implementingClass.extendsOrImplements(referencedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #22
Source File: ExceptionAdder.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add a class constant to the constant pool.
    constantAdder.visitClassConstant(clazz, classConstant);

    // Add the index of the class constant to the list of exceptions.
    exceptionsAttributeEditor.addException(constantAdder.getConstantIndex());
}
 
Example #23
Source File: ClassConstantValueFactory.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Create a Class reference instead of a reference to the class.
    value = valueFactory.createReferenceValue(ClassConstants.NAME_JAVA_LANG_CLASS,
                                              classConstant.javaLangClassClass,
                                              false);
}
 
Example #24
Source File: ExceptClassConstantFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (!classConstant.getName(clazz).equals(exceptClassName))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #25
Source File: ImplementingClassConstantFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !implementingClass.extendsOrImplements(referencedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #26
Source File: ImplementedClassConstantFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    Clazz referencedClass = classConstant.referencedClass;
    if (referencedClass == null ||
        !referencedClass.extendsOrImplements(implementedClass))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}
 
Example #27
Source File: ExceptionAdder.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Add a class constant to the constant pool.
    constantAdder.visitClassConstant(clazz, classConstant);

    // Add the index of the class constant to the list of exceptions.
    exceptionsAttributeEditor.addException(constantAdder.getConstantIndex());
}
 
Example #28
Source File: ClassRenamer.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Update the Class entry if required.
    String newName = ClassObfuscator.newClassName(clazz);
    if (newName != null)
    {
        // Refer to a new Utf8 entry.
        classConstant.u2nameIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newName);
    }
}
 
Example #29
Source File: ClassConstantValueFactory.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    // Create a Class reference instead of a reference to the class.
    value = valueFactory.createReferenceValue(ClassConstants.NAME_JAVA_LANG_CLASS,
                                              classConstant.javaLangClassClass,
                                              false);
}
 
Example #30
Source File: ExceptClassConstantFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (!classConstant.getName(clazz).equals(exceptClassName))
    {
        constantVisitor.visitClassConstant(clazz, classConstant);
    }
}