mirror of
https://github.com/Guardsquare/proguard.git
synced 2026-03-13 09:50:34 +08:00
Compare commits
1 Commits
v7.3.2
...
record-att
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5cf8ddde5 |
@@ -22,7 +22,7 @@ package proguard.obfuscate;
|
|||||||
|
|
||||||
import proguard.classfile.*;
|
import proguard.classfile.*;
|
||||||
import proguard.classfile.attribute.*;
|
import proguard.classfile.attribute.*;
|
||||||
import proguard.classfile.attribute.visitor.AttributeVisitor;
|
import proguard.classfile.attribute.visitor.*;
|
||||||
import proguard.classfile.visitor.*;
|
import proguard.classfile.visitor.*;
|
||||||
import proguard.util.Processable;
|
import proguard.util.Processable;
|
||||||
|
|
||||||
@@ -39,7 +39,8 @@ import java.util.Arrays;
|
|||||||
public class AttributeShrinker
|
public class AttributeShrinker
|
||||||
implements ClassVisitor,
|
implements ClassVisitor,
|
||||||
MemberVisitor,
|
MemberVisitor,
|
||||||
AttributeVisitor
|
AttributeVisitor,
|
||||||
|
RecordComponentInfoVisitor
|
||||||
{
|
{
|
||||||
// Implementations for ClassVisitor.
|
// Implementations for ClassVisitor.
|
||||||
|
|
||||||
@@ -83,6 +84,13 @@ implements ClassVisitor,
|
|||||||
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
||||||
|
|
||||||
|
|
||||||
|
public void visitRecordAttribute(Clazz clazz, RecordAttribute recordAttribute)
|
||||||
|
{
|
||||||
|
// Compact any attributes of the components.
|
||||||
|
recordAttribute.componentsAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
|
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
|
||||||
{
|
{
|
||||||
// Compact the attributes array.
|
// Compact the attributes array.
|
||||||
@@ -92,6 +100,17 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for RecordComponentInfoVisitor.
|
||||||
|
|
||||||
|
public void visitRecordComponentInfo(Clazz clazz, RecordComponentInfo recordComponentInfo)
|
||||||
|
{
|
||||||
|
// Compact the attributes array.
|
||||||
|
recordComponentInfo.u2attributesCount =
|
||||||
|
shrinkArray(recordComponentInfo.attributes,
|
||||||
|
recordComponentInfo.u2attributesCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Small utility methods.
|
// Small utility methods.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,9 +44,12 @@ import proguard.util.ArrayUtil;
|
|||||||
*/
|
*/
|
||||||
public class TargetClassChanger
|
public class TargetClassChanger
|
||||||
implements ClassVisitor,
|
implements ClassVisitor,
|
||||||
|
|
||||||
|
// Implementation interfaces.
|
||||||
ConstantVisitor,
|
ConstantVisitor,
|
||||||
MemberVisitor,
|
MemberVisitor,
|
||||||
AttributeVisitor,
|
AttributeVisitor,
|
||||||
|
RecordComponentInfoVisitor,
|
||||||
LocalVariableInfoVisitor,
|
LocalVariableInfoVisitor,
|
||||||
LocalVariableTypeInfoVisitor,
|
LocalVariableTypeInfoVisitor,
|
||||||
AnnotationVisitor,
|
AnnotationVisitor,
|
||||||
@@ -305,6 +308,13 @@ implements ClassVisitor,
|
|||||||
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
||||||
|
|
||||||
|
|
||||||
|
public void visitRecordAttribute(Clazz clazz, RecordAttribute recordAttribute)
|
||||||
|
{
|
||||||
|
// Fix the record component attributes.
|
||||||
|
recordAttribute.componentsAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
|
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
|
||||||
{
|
{
|
||||||
// Change the references of the attributes.
|
// Change the references of the attributes.
|
||||||
@@ -354,6 +364,18 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for RecordComponentInfoVisitor.
|
||||||
|
|
||||||
|
public void visitRecordComponentInfo(Clazz clazz, RecordComponentInfo recordComponentInfo)
|
||||||
|
{
|
||||||
|
// Don't change the referenced field; it's still the original one
|
||||||
|
// in this class.
|
||||||
|
|
||||||
|
// Change the references of the attributes.
|
||||||
|
recordComponentInfo.attributesAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implementations for LocalVariableInfoVisitor.
|
// Implementations for LocalVariableInfoVisitor.
|
||||||
|
|
||||||
public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
|
public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class ClassShrinker
|
|||||||
implements ClassVisitor,
|
implements ClassVisitor,
|
||||||
MemberVisitor,
|
MemberVisitor,
|
||||||
AttributeVisitor,
|
AttributeVisitor,
|
||||||
|
RecordComponentInfoVisitor,
|
||||||
AnnotationVisitor,
|
AnnotationVisitor,
|
||||||
ElementValueVisitor
|
ElementValueVisitor
|
||||||
{
|
{
|
||||||
@@ -233,6 +234,18 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void visitRecordAttribute(Clazz clazz, RecordAttribute recordAttribute)
|
||||||
|
{
|
||||||
|
// Shrink the array of RecordComponentInfo objects.
|
||||||
|
recordAttribute.u2componentsCount =
|
||||||
|
shrinkArray(recordAttribute.components,
|
||||||
|
recordAttribute.u2componentsCount);
|
||||||
|
|
||||||
|
// Shrink the attributes of the remaining components.
|
||||||
|
recordAttribute.componentsAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
|
public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
|
||||||
{
|
{
|
||||||
// Shrink the array of InnerClassesInfo objects.
|
// Shrink the array of InnerClassesInfo objects.
|
||||||
@@ -318,6 +331,20 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for RecordComponentInfoVisitor.
|
||||||
|
|
||||||
|
public void visitRecordComponentInfo(Clazz clazz, RecordComponentInfo recordComponentInfo)
|
||||||
|
{
|
||||||
|
// Shrink the attributes array.
|
||||||
|
recordComponentInfo.u2attributesCount =
|
||||||
|
shrinkArray(recordComponentInfo.attributes,
|
||||||
|
recordComponentInfo.u2attributesCount);
|
||||||
|
|
||||||
|
// Shrink the remaining attributes.
|
||||||
|
recordComponentInfo.attributesAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implementations for AnnotationVisitor.
|
// Implementations for AnnotationVisitor.
|
||||||
|
|
||||||
public void visitAnnotation(Clazz clazz, Annotation annotation)
|
public void visitAnnotation(Clazz clazz, Annotation annotation)
|
||||||
|
|||||||
@@ -857,15 +857,6 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void visitSourceDebugExtensionAttribute(Clazz clazz,
|
|
||||||
SourceDebugExtensionAttribute sourceDebugExtensionAttribute)
|
|
||||||
{
|
|
||||||
markAsUsed(sourceDebugExtensionAttribute);
|
|
||||||
|
|
||||||
markConstant(clazz, sourceDebugExtensionAttribute.u2attributeNameIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
|
public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
|
||||||
{
|
{
|
||||||
// Don't mark the attribute and its name here. We may mark it in
|
// Don't mark the attribute and its name here. We may mark it in
|
||||||
@@ -891,6 +882,26 @@ implements ClassVisitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void visitSourceDebugExtensionAttribute(Clazz clazz, SourceDebugExtensionAttribute sourceDebugExtensionAttribute)
|
||||||
|
{
|
||||||
|
markAsUsed(sourceDebugExtensionAttribute);
|
||||||
|
|
||||||
|
markConstant(clazz, sourceDebugExtensionAttribute.u2attributeNameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void visitRecordAttribute(Clazz clazz, RecordAttribute recordAttribute)
|
||||||
|
{
|
||||||
|
markAsUsed(recordAttribute);
|
||||||
|
|
||||||
|
markConstant(clazz, recordAttribute.u2attributeNameIndex);
|
||||||
|
|
||||||
|
// Don't mark the components yet. We may mark them later, in
|
||||||
|
// RecordComponentUsageMarker.
|
||||||
|
//recordAttribute.componentsAccept(clazz, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
|
public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
|
||||||
{
|
{
|
||||||
// Don't mark the attribute and its name yet. We may mark it later, in
|
// Don't mark the attribute and its name yet. We may mark it later, in
|
||||||
|
|||||||
108
base/src/proguard/shrink/RecordComponentUsageMarker.java
Normal file
108
base/src/proguard/shrink/RecordComponentUsageMarker.java
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* ProGuard -- shrinking, optimization, obfuscation, and preverification
|
||||||
|
* of Java bytecode.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2020 Guardsquare NV
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
|
* Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
package proguard.shrink;
|
||||||
|
|
||||||
|
import proguard.classfile.*;
|
||||||
|
import proguard.classfile.attribute.*;
|
||||||
|
import proguard.classfile.attribute.visitor.*;
|
||||||
|
import proguard.classfile.constant.*;
|
||||||
|
import proguard.classfile.constant.visitor.ConstantVisitor;
|
||||||
|
import proguard.classfile.visitor.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This RecordComponentInfoVisitor marks all record components that
|
||||||
|
* it visits and whose corresponding fields have been marked before.
|
||||||
|
*
|
||||||
|
* @see ClassUsageMarker
|
||||||
|
*
|
||||||
|
* @author Eric Lafortune
|
||||||
|
*/
|
||||||
|
public class RecordComponentUsageMarker
|
||||||
|
implements RecordComponentInfoVisitor,
|
||||||
|
MemberVisitor,
|
||||||
|
ConstantVisitor
|
||||||
|
{
|
||||||
|
private final ClassUsageMarker classUsageMarker;
|
||||||
|
|
||||||
|
// Field acting as a return parameter.
|
||||||
|
private boolean fieldUsed;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new InnerUsageMarker.
|
||||||
|
* @param classUsageMarker the marker to mark and check the classes and
|
||||||
|
* class members.
|
||||||
|
*/
|
||||||
|
public RecordComponentUsageMarker(ClassUsageMarker classUsageMarker)
|
||||||
|
{
|
||||||
|
this.classUsageMarker = classUsageMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for RecordComponentInfoVisitor.
|
||||||
|
|
||||||
|
public void visitRecordComponentInfo(Clazz clazz, RecordComponentInfo recordComponentInfo)
|
||||||
|
{
|
||||||
|
// Is the field that corresponds to the component used?
|
||||||
|
fieldUsed = false;
|
||||||
|
recordComponentInfo.referencedFieldAccept(clazz, this);
|
||||||
|
if (fieldUsed)
|
||||||
|
{
|
||||||
|
// Mark the component.
|
||||||
|
classUsageMarker.markAsUsed(recordComponentInfo);
|
||||||
|
|
||||||
|
// Mark its name and descriptor.
|
||||||
|
markConstant(clazz, recordComponentInfo.u2nameIndex);
|
||||||
|
markConstant(clazz, recordComponentInfo.u2descriptorIndex);
|
||||||
|
|
||||||
|
// Mark its attributes.
|
||||||
|
recordComponentInfo.attributesAccept(clazz, classUsageMarker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for MemberVisitor.
|
||||||
|
|
||||||
|
public void visitProgramField(ProgramClass programClass, ProgramField programField)
|
||||||
|
{
|
||||||
|
fieldUsed = classUsageMarker.isUsed(programField);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implementations for ConstantVisitor.
|
||||||
|
|
||||||
|
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
|
||||||
|
{
|
||||||
|
classUsageMarker.markAsUsed(utf8Constant);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Small utility methods.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the given constant pool entry of the given class. This includes
|
||||||
|
* visiting any other referenced constant pool entries.
|
||||||
|
*/
|
||||||
|
private void markConstant(Clazz clazz, int index)
|
||||||
|
{
|
||||||
|
clazz.constantPoolEntryAccept(index, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -138,6 +138,12 @@ public class UsageMarker
|
|||||||
new KotlinModuleUsageMarker(simpleUsageMarker))));
|
new KotlinModuleUsageMarker(simpleUsageMarker))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark the record metadata.
|
||||||
|
programClassPool.classesAccept(
|
||||||
|
new AllAttributeVisitor(
|
||||||
|
new AllRecordComponentInfoVisitor(
|
||||||
|
new RecordComponentUsageMarker(classUsageMarker))));
|
||||||
|
|
||||||
// Check if the Gson optimization is enabled.
|
// Check if the Gson optimization is enabled.
|
||||||
StringMatcher filter = configuration.optimizations != null ?
|
StringMatcher filter = configuration.optimizations != null ?
|
||||||
new ListParser(new NameParser()).parse(configuration.optimizations) :
|
new ListParser(new NameParser()).parse(configuration.optimizations) :
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ attributes. You can keep them with the
|
|||||||
: Specifies the name of the source directory from which the class file was
|
: Specifies the name of the source directory from which the class file was
|
||||||
compiled.
|
compiled.
|
||||||
|
|
||||||
|
`Record`
|
||||||
|
: Specifies the components of a record class. Code may access this information
|
||||||
|
by reflection.
|
||||||
|
|
||||||
`InnerClasses`
|
`InnerClasses`
|
||||||
: Specifies the relationship between a class and its inner classes and outer
|
: Specifies the relationship between a class and its inner classes and outer
|
||||||
classes. Other than this and the naming convention with a '\$' separator
|
classes. Other than this and the naming convention with a '\$' separator
|
||||||
@@ -135,7 +139,7 @@ ProGuard automatically keeps the following essential attributes, processing
|
|||||||
them as necessary. We're listing them for the sake of completeness:
|
them as necessary. We're listing them for the sake of completeness:
|
||||||
|
|
||||||
`ConstantValue`
|
`ConstantValue`
|
||||||
: Specifies a constant integer, float, class, string, etc.
|
: Specifies a constant integer, float, class, string, etc.
|
||||||
|
|
||||||
`Code`
|
`Code`
|
||||||
: Specifies the actual bytecode of a method.
|
: Specifies the actual bytecode of a method.
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
## Version 7.1
|
||||||
|
|
||||||
|
| Version| Issue | Module | Explanation
|
||||||
|
|--------|----------|----------|----------------------------------
|
||||||
|
| 7.1.x | PGD-0064 | CORE | Added support for Java 14 and 15.
|
||||||
|
| 7.1.x | PGD-0064 | CORE | Added support for record attributes.
|
||||||
|
| 7.1.x | DGD-2390 | CORE | Fixed storage and alignment of uncompressed zip entries.
|
||||||
|
| 7.1.x | DGD-2338 | CORE | Fixed processing of constant boolean arrays.
|
||||||
|
|
||||||
## Version 7.0 (Jun 2020)
|
## Version 7.0 (Jun 2020)
|
||||||
|
|
||||||
| Version| Issue | Module | Explanation
|
| Version| Issue | Module | Explanation
|
||||||
|
|||||||
@@ -2,5 +2,10 @@ gsonVersion = 2.8.5
|
|||||||
kotlinVersion = 1.3.31
|
kotlinVersion = 1.3.31
|
||||||
kotlinxMetadataVersion = 0.1.0
|
kotlinxMetadataVersion = 0.1.0
|
||||||
target = 1.8
|
target = 1.8
|
||||||
|
|
||||||
|
# Optionally compile the WTK plugin.
|
||||||
wtkDir = /usr/local/java/wtk2.1
|
wtkDir = /usr/local/java/wtk2.1
|
||||||
wtkHome = /usr/local/java/wtk
|
wtkHome = /usr/local/java/wtk
|
||||||
|
|
||||||
|
# Optionally set up a composite build with ProGuardCORE.
|
||||||
|
#proguardCoreDir = ../proguard-core
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasProperty('proguardCoreDir'))
|
||||||
|
{
|
||||||
|
includeBuild proguardCoreDir
|
||||||
|
}
|
||||||
|
|
||||||
rootProject.name = 'parent'
|
rootProject.name = 'parent'
|
||||||
|
|
||||||
include 'base'
|
include 'base'
|
||||||
|
|||||||
Reference in New Issue
Block a user