proguard.classfile.ProgramClass Java Examples

The following examples show how to use proguard.classfile.ProgramClass. 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 visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Compute the new type name.
    String typeName    = clazz.getString(annotation.u2typeIndex);
    String newTypeName = newDescriptor(typeName,
                                       annotation.referencedClasses);

    if (!typeName.equals(newTypeName))
    {
        // Refer to a new Utf8 entry.
        annotation.u2typeIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newTypeName);
    }

    // Fix the element values.
    annotation.elementValuesAccept(clazz, this);
}
 
Example #2
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 #3
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
{
    // Does the string refer to a class, due to a Class.forName construct?
    Clazz referencedClass  = stringConstant.referencedClass;
    Member referencedMember = stringConstant.referencedMember;
    if (referencedClass  != null &&
        referencedMember == null)
    {
        // Reconstruct the new class name.
        String externalClassName    = stringConstant.getString(clazz);
        String internalClassName    = ClassUtil.internalClassName(externalClassName);
        String newInternalClassName = newClassName(internalClassName,
                                                   referencedClass);

        // Update the String entry if required.
        if (!newInternalClassName.equals(internalClassName))
        {
            String newExternalClassName = ClassUtil.externalClassName(newInternalClassName);

            // Refer to a new Utf8 entry.
            stringConstant.u2stringIndex =
                new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newExternalClassName);
        }
    }
}
 
Example #4
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant)
{
    // Do we know the referenced field?
    Member referencedMember = fieldrefConstant.referencedMember;
    if (referencedMember != null)
    {
        Clazz referencedClass = fieldrefConstant.referencedClass;

        // Does it have a new name or type?
        String newName = referencedMember.getName(referencedClass);
        String newType = referencedMember.getDescriptor(referencedClass);

        if (!fieldrefConstant.getName(clazz).equals(newName) ||
            !fieldrefConstant.getType(clazz).equals(newType))
        {
            if (DEBUG)
            {
                debug(clazz, fieldrefConstant, referencedClass, referencedMember);
            }

            // Update the name and type index.
            fieldrefConstant.u2nameAndTypeIndex =
                new ConstantPoolEditor((ProgramClass)clazz).addNameAndTypeConstant(newName, newType);
        }
    }
}
 
Example #5
Source File: NonPrivateMemberMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Mark all referenced class members in different classes.
    programClass.constantPoolEntriesAccept(this);

    // Explicitly mark the <clinit> method.
    programClass.methodAccept(ClassConstants.INTERNAL_METHOD_NAME_CLINIT,
                              ClassConstants.INTERNAL_METHOD_TYPE_CLINIT,
                              this);

    // Explicitly mark the parameterless <init> method.
    programClass.methodAccept(ClassConstants.INTERNAL_METHOD_NAME_INIT,
                              ClassConstants.INTERNAL_METHOD_TYPE_INIT,
                              this);

    // Mark all methods that may have implementations.
    programClass.methodsAccept(filteredMethodMarker);
}
 
Example #6
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    stackSizesMayHaveChanged = false;

    // Fix the constant pool entries.
    for (int index = 1; index < programClass.u2constantPoolCount; index++)
    {
        Constant constant = programClass.constantPool[index];
        if (constant != null)
        {
            // Fix the entry, replacing it entirely if needed.
            this.constantIndex = index;

            constant.accept(programClass, this);
        }
    }

    // Fix the class members.
    programClass.fieldsAccept(this);
    programClass.methodsAccept(this);

    // Fix the attributes.
    programClass.attributesAccept(this);
}
 
Example #7
Source File: MappingPrinter.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)
{
    // Special cases: <clinit> and <init> are always kept unchanged.
    // We can ignore them here.
    String name = programMethod.getName(programClass);
    if (name.equals(ClassConstants.INTERNAL_METHOD_NAME_CLINIT) ||
        name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))
    {
        return;
    }

    String newName = MemberObfuscator.newMemberName(programMethod);
    if (newName != null)
    {
        ps.println("    " +
                   lineNumberRange(programClass, programMethod) +
                   ClassUtil.externalFullMethodDescription(
                       programClass.getName(),
                       0,
                       programMethod.getName(programClass),
                       programMethod.getDescriptor(programClass)) +
                   " -> " +
                   newName);
    }
}
 
Example #8
Source File: ClassObfuscator.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Does the class already have a new name?
    String newClassName = newClassName(programClass);
    if (newClassName != null)
    {
        // Remember not to use this name.
        classNamesToAvoid.add(mixedCaseClassName(newClassName));

        // Are we not aggressively repackaging all obfuscated classes?
        if (repackageClasses == null ||
            !allowAccessModification)
        {
            String className = programClass.getName();

            // Keep the package name for all other classes in the same
            // package. Do this recursively if we're not doing any
            // repackaging.
            mapPackageName(className,
                           newClassName,
                           repackageClasses        == null &&
                           flattenPackageHierarchy == null);
        }
    }
}
 
Example #9
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 #10
Source File: ClassPrinter.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)
{
    println(visitorInfo(programMethod) + " " +
            "Method:       " +
            programMethod.getName(programClass) +
            programMethod.getDescriptor(programClass));

    indent();
    println("Access flags: 0x" + Integer.toHexString(programMethod.u2accessFlags));
    println("  = " +
            ClassUtil.externalFullMethodDescription(programClass.getName(),
                                                    programMethod.u2accessFlags,
                                                    programMethod.getName(programClass),
                                                    programMethod.getDescriptor(programClass)));

    visitMember(programClass, programMethod);
    outdent();
}
 
Example #11
Source File: ClassRenamer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMember(ProgramClass programClass,
                                 ProgramMember programMember)
{
    // Has the class member name changed?
    String name    = programMember.getName(programClass);
    String newName = MemberObfuscator.newMemberName(programMember);
    if (newName != null &&
        !newName.equals(name))
    {
        programMember.u2nameIndex =
            new ConstantPoolEditor(programClass).addUtf8Constant(newName);
    }
}
 
Example #12
Source File: ClassReferenceInitializer.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)
{
    programField.referencedClass =
        findReferencedClass(programClass.getName(),
                            programField.getDescriptor(programClass));

    // Initialize the attributes.
    programField.attributesAccept(programClass, this);
}
 
Example #13
Source File: NameMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    keepClassName(programClass);

    // Make sure any outer class names are kept as well.
    programClass.attributesAccept(this);
}
 
Example #14
Source File: ClassPrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private void visitMember(ProgramClass programClass, ProgramMember programMember)
{
    if (programMember.u2attributesCount > 0)
    {
        println("Class member attributes (count = " + programMember.u2attributesCount + "):");
        programMember.attributesAccept(programClass, this);
    }
}
 
Example #15
Source File: ClassSubHierarchyInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Add this class to the subclasses of its superclass.
    addSubclass(programClass, programClass.getSuperClass());

    // Add this class to the subclasses of its interfaces.
    for (int index = 0; index < programClass.u2interfacesCount; index++)
    {
        addSubclass(programClass, programClass.getInterface(index));
    }
}
 
Example #16
Source File: ElementValuesEditor.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ElementValuesEditor that will edit element values in the
 * given target annotation.
 */
public ElementValuesEditor(ProgramClass targetClass,
                           Annotation   targetAnnotation,
                           boolean      replaceElementValues)
{
    this.targetClass             = targetClass;
    this.targetAnnotation        = targetAnnotation;
    this.targetArrayElementValue = null;
    this.replaceElementValues    = replaceElementValues;
}
 
Example #17
Source File: AttributeShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
{
    // Compact the attributes array.
    programMember.u2attributesCount =
        shrinkArray(programMember.attributes,
                    programMember.u2attributesCount);

    // Compact any attributes of the remaining attributes.
    programMember.attributesAccept(programClass, this);
}
 
Example #18
Source File: ConstantMemberFilter.java    From java-n-IDE-for-Android 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 #19
Source File: VerticalClassMerger.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Try inlining all immediate subclasses into this class.
    programClass.subclassesAccept(new ClassMerger(programClass,
                                                  allowAccessModification,
                                                  mergeInterfacesAggressively,
                                                  extraClassVisitor));
}
 
Example #20
Source File: LocalVariableTypeInfoAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new LocalVariableTypeInfoAdder that will copy line numbers into the
 * given target line number table.
 */
public LocalVariableTypeInfoAdder(ProgramClass                    targetClass,
                                  LocalVariableTypeTableAttribute targetLocalVariableTypeTableAttribute)
{
    this.constantAdder                         = new ConstantAdder(targetClass);
    this.localVariableTypeTableAttributeEditor = new LocalVariableTypeTableAttributeEditor(targetLocalVariableTypeTableAttribute);
}
 
Example #21
Source File: AnnotationAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AnnotationAdder that will copy annotations into the given
 * target annotation element value.
 */
public AnnotationAdder(ProgramClass targetClass,
                       AnnotationElementValue targetAnnotationElementValue)
{
    this.targetClass                         = targetClass;
    this.targetAnnotationElementValue        = targetAnnotationElementValue;
    this.annotationsAttributeEditor          = null;
    this.parameterAnnotationsAttributeEditor = null;

    constantAdder = new ConstantAdder(targetClass);
}
 
Example #22
Source File: DescriptorKeepChecker.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)
{
    //referencingClass  = programClass;
    //referencingMember = programField;
    //isField           = true;
    //
    // Don't check the type, because it is not required for introspection.
    //programField.referencedClassesAccept(this);
}
 
Example #23
Source File: ReferencedClassVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
{
    // Let the visitor visit the classes referenced in the descriptor string.
    programMember.referencedClassesAccept(classVisitor);

    // Visit the attributes.
    programMember.attributesAccept(programClass, this);
}
 
Example #24
Source File: ClassAccessFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (accepted(programClass.getAccessFlags()))
    {
        classVisitor.visitProgramClass(programClass);
    }
}
 
Example #25
Source File: ElementValuesEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ElementValuesEditor that will edit element values in the
 * given target annotation.
 */
public ElementValuesEditor(ProgramClass targetClass,
                           Annotation   targetAnnotation,
                           boolean      replaceElementValues)
{
    this.targetClass             = targetClass;
    this.targetAnnotation        = targetAnnotation;
    this.targetArrayElementValue = null;
    this.replaceElementValues    = replaceElementValues;
}
 
Example #26
Source File: MemberAccessFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    if (accepted(programMethod.getAccessFlags()))
    {
        memberVisitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example #27
Source File: AttributeAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AttributeAdder that will copy attributes into the given
 * target class member.
 */
public AttributeAdder(ProgramClass  targetClass,
                      ProgramMember targetMember,
                      boolean       replaceAttributes)
{
    this(targetClass, targetMember, null, replaceAttributes);
}
 
Example #28
Source File: UsagePrinter.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)
{
    if (usageMarker.isUsed(programField) ^ printUnusedItems)
    {
        printClassNameHeader();

        ps.println("    " +
                   lineNumberRange(programClass, programField) +
                   ClassUtil.externalFullFieldDescription(
                       programField.getAccessFlags(),
                       programField.getName(programClass),
                       programField.getDescriptor(programClass)));
    }
}
 
Example #29
Source File: ClassVersionSetter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    if (programClass.u4version > classVersion &&
        newerClassVersions != null)
    {
        newerClassVersions.add(new Integer(programClass.u4version));
    }

    programClass.u4version = classVersion;
}
 
Example #30
Source File: StringSharer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Replace name strings in the constant pool by shared strings.
    programClass.constantPoolEntriesAccept(this);

    // Replace attribute name strings in the constant pool by internalized
    // strings.
    programClass.attributesAccept(this);
}