diff options
author | delphinemartin <delphinemartin@google.com> | 2014-04-24 17:39:27 +0200 |
---|---|---|
committer | delphinemartin <delphinemartin@google.com> | 2014-05-22 15:16:54 +0200 |
commit | 84eabbb9d86d8b00abbfc3987d2fdfeab7144cb8 (patch) | |
tree | 5c4c62f8a615e601261da16ef713183a04733fc0 | |
parent | ff052503f73b9bfb0b0ae13cde56b202121974c7 (diff) | |
download | toolchain_jack-84eabbb9d86d8b00abbfc3987d2fdfeab7144cb8.zip toolchain_jack-84eabbb9d86d8b00abbfc3987d2fdfeab7144cb8.tar.gz toolchain_jack-84eabbb9d86d8b00abbfc3987d2fdfeab7144cb8.tar.bz2 |
Fixed support to remove the thrown exceptions of a method while obfuscating.
Previous support was not complete since it was not working when shrobbing and
dex generation were not done in the same plan.
This support removes the information from the IR, so after the obfuscation
phase, if the flags do not explicitely keep it, the thrown exceptions of a
method cannot be retrieved.
Bug: 11803482
Change-Id: I78efd58fd1b1b0f96ff1df5a8b046c23f1477c93
6 files changed, 84 insertions, 21 deletions
diff --git a/jack/.settings/findbugs-exclude.xml b/jack/.settings/findbugs-exclude.xml index df51fa3..16eb0cd 100644 --- a/jack/.settings/findbugs-exclude.xml +++ b/jack/.settings/findbugs-exclude.xml @@ -7,6 +7,10 @@ <Class name="com.android.jack.shrob.shrink.Tracer"/> <Bug code="EC"/> </Match> +<Match> + <Class name="com.android.jack.shrob.obfuscation.annotation.RemoveThrownException"/> + <Bug code="Nm"/> +</Match> <!-- Ignore Antlr generated files --> <Match> <Class name="~com\.android\.jack\.shrob\.proguard\.ProguardLexer.*"/> diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java index 8b2f9f6..171e35e 100644 --- a/jack/src/com/android/jack/Jack.java +++ b/jack/src/com/android/jack/Jack.java @@ -119,6 +119,8 @@ import com.android.jack.shrob.obfuscation.annotation.RemoveEnclosingMethod; import com.android.jack.shrob.obfuscation.annotation.RemoveEnclosingType; import com.android.jack.shrob.obfuscation.annotation.RemoveGenericSignature; import com.android.jack.shrob.obfuscation.annotation.RemoveLocalVariableGenericSignature; +import com.android.jack.shrob.obfuscation.annotation.RemoveThrownException; +import com.android.jack.shrob.obfuscation.annotation.ThrownExceptionRemover; import com.android.jack.shrob.obfuscation.annotation.TypeAnnotationRemover; import com.android.jack.shrob.obfuscation.annotation.TypeEnclosingMethodRemover; import com.android.jack.shrob.obfuscation.annotation.TypeEnclosingTypeRemover; @@ -428,6 +430,9 @@ public abstract class Jack { if (!options.flags.keepAttribute("LocalVariableTypeTable")) { request.addFeature(RemoveLocalVariableGenericSignature.class); } + if (!options.flags.keepAttribute("Exceptions")) { + request.addFeature(RemoveThrownException.class); + } } if (config.get(TypeAndMemberLister.TYPE_AND_MEMBER_LISTING).booleanValue()) { request.addProduction(TypeAndMemberListing.class); @@ -1309,6 +1314,9 @@ public abstract class Jack { if (features.contains(RemoveAnnotationDefaultValue.class)) { methodPlan.append(AnnotationDefaultValueRemover.class); } + if (features.contains(RemoveThrownException.class)) { + methodPlan.append(ThrownExceptionRemover.class); + } } } } diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java index 68229a7..49b8877 100644 --- a/jack/src/com/android/jack/Options.java +++ b/jack/src/com/android/jack/Options.java @@ -17,7 +17,6 @@ package com.android.jack; import com.android.jack.backend.dex.FieldInitializerRemover; -import com.android.jack.backend.dex.annotations.ReflectAnnotationsAdder; import com.android.jack.backend.dex.rop.CodeItemBuilder; import com.android.jack.config.id.JavaVersionPropertyId; import com.android.jack.ir.ast.JMethod; @@ -449,8 +448,6 @@ public class Options { configBuilder.pushDefaultLocation(new StringLocation("proguard flags")); if (flags != null) { - configBuilder.set(ReflectAnnotationsAdder.EMIT_ANNOTATION_THROWS, - flags.keepAttribute("Exceptions")); configBuilder.set(AnnotationRemover.EMIT_RUNTIME_INVISIBLE_ANNOTATION, flags.keepAttribute("RuntimeInvisibleAnnotations")); configBuilder.set(AnnotationRemover.EMIT_RUNTIME_VISIBLE_ANNOTATION, diff --git a/jack/src/com/android/jack/backend/dex/annotations/ReflectAnnotationsAdder.java b/jack/src/com/android/jack/backend/dex/annotations/ReflectAnnotationsAdder.java index ad6c9bc..e13200c 100644 --- a/jack/src/com/android/jack/backend/dex/annotations/ReflectAnnotationsAdder.java +++ b/jack/src/com/android/jack/backend/dex/annotations/ReflectAnnotationsAdder.java @@ -60,8 +60,6 @@ import com.android.sched.schedulable.RunnableSchedulable; import com.android.sched.schedulable.Transform; import com.android.sched.schedulable.With; import com.android.sched.util.config.HasKeyId; -import com.android.sched.util.config.ThreadConfig; -import com.android.sched.util.config.id.BooleanPropertyId; import java.util.ArrayList; import java.util.Collections; @@ -83,7 +81,7 @@ import javax.annotation.Nonnull; unprotect = @With(remove = ReflectAnnotations.class)) public class ReflectAnnotationsAdder implements RunnableSchedulable<JDefinedClassOrInterface> { - private class Visitor extends JVisitor { + private static class Visitor extends JVisitor { @Nonnull private final TransformationRequest request; @@ -167,9 +165,7 @@ public class ReflectAnnotationsAdder implements RunnableSchedulable<JDefinedClas @Override public void endVisit(@Nonnull JMethod x) { - if (addAnnotationThrows) { - addThrows(x); - } + addThrows(x); GenericSignature marker = x.getMarker(GenericSignature.class); if (marker != null) { String genericSignature = marker.getGenericSignature(); @@ -374,18 +370,6 @@ public class ReflectAnnotationsAdder implements RunnableSchedulable<JDefinedClas } } - @Nonnull - public static final BooleanPropertyId EMIT_ANNOTATION_SIG = BooleanPropertyId.create( - "jack.annotation.signature", "Emit annotation signature") - .addDefaultValue(Boolean.TRUE); - - @Nonnull - public static final BooleanPropertyId EMIT_ANNOTATION_THROWS = BooleanPropertyId.create( - "jack.annotation.throws", "Emit annotation throws").addDefaultValue(Boolean.TRUE); - - private final boolean addAnnotationThrows = - ThreadConfig.get(EMIT_ANNOTATION_THROWS).booleanValue(); - @Override public synchronized void run(@Nonnull JDefinedClassOrInterface declaredType) throws Exception { TransformationRequest tr = new TransformationRequest(declaredType); diff --git a/jack/src/com/android/jack/shrob/obfuscation/annotation/RemoveThrownException.java b/jack/src/com/android/jack/shrob/obfuscation/annotation/RemoveThrownException.java new file mode 100644 index 0000000..c8612b3 --- /dev/null +++ b/jack/src/com/android/jack/shrob/obfuscation/annotation/RemoveThrownException.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.shrob.obfuscation.annotation; + +import com.android.sched.item.Description; +import com.android.sched.item.Feature; + +/** + * Represents the removal of thrown exceptions of a method. + */ +@Description("The removal of thrown exceptions of a method") +public class RemoveThrownException implements Feature { + +} diff --git a/jack/src/com/android/jack/shrob/obfuscation/annotation/ThrownExceptionRemover.java b/jack/src/com/android/jack/shrob/obfuscation/annotation/ThrownExceptionRemover.java new file mode 100644 index 0000000..415958e --- /dev/null +++ b/jack/src/com/android/jack/shrob/obfuscation/annotation/ThrownExceptionRemover.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.shrob.obfuscation.annotation; + +import com.android.jack.backend.dex.annotations.tag.ReflectAnnotations; +import com.android.jack.ir.ast.JMethod; +import com.android.jack.ir.ast.marker.ThrownExceptionMarker; +import com.android.sched.item.Description; +import com.android.sched.schedulable.Constraint; +import com.android.sched.schedulable.RunnableSchedulable; +import com.android.sched.schedulable.Transform; + +import javax.annotation.Nonnull; + +/** + * A {@link RunnableSchedulable} that removes thrown exceptions from methods. + */ +@Description("Removes thrown exception from methods") +@Constraint(no = ReflectAnnotations.class) +@Transform(remove = ThrownExceptionMarker.class) +public class ThrownExceptionRemover implements RunnableSchedulable<JMethod> { + + @Override + public void run(@Nonnull JMethod method) throws Exception { + method.removeMarker(ThrownExceptionMarker.class); + } + +} |