From fa14e3395338d8a4795a316034679092f1475839 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 09:00:14 +0300 Subject: [PATCH 01/22] Bump version to 0.2.0 --- version.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.properties b/version.properties index 0d65f7d..4869629 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ version.major=0 -version.minor=1 -version.patch=8 +version.minor=2 +version.patch=0 version.snapshot=false version.dryRun=false From 1c5dea95f53738569b2ed43ee13bad7949986237 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 09:00:31 +0300 Subject: [PATCH 02/22] Fix a warning --- gradle-plugin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index 62b8ee5..54387b0 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -15,7 +15,7 @@ dependencies { compile gradleApi() compile project(':processor') - compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinVersion" + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" compileOnly "com.android.tools.build:gradle:$androidToolsVersion" compileOnly "com.android.tools.build:gradle-api:$androidToolsVersion" From 90a2a8a39a8183d22767b43c574447a683d90d4a Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 09:01:08 +0300 Subject: [PATCH 03/22] Bump Grip version to 0.6.0-beta --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0a362c3..f0df066 100644 --- a/build.gradle +++ b/build.gradle @@ -32,8 +32,8 @@ allprojects { } ext { - asmVersion = '5.2' - gripVersion = '0.5.3-beta' + asmVersion = '6.0' + gripVersion = '0.6.0-beta' logbackVersion = '1.2.3' junitVersion = '4.12' From 39361f8e33936f1dfbad6623826243526b05e010 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 13:15:00 +0300 Subject: [PATCH 04/22] Back to Java 6 in Gradle plugin --- gradle-plugin/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index 54387b0..61975ac 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -8,14 +8,14 @@ apply plugin: 'kotlin' apply plugin: 'bintray' apply plugin: 'idea' -targetCompatibility = JavaVersion.VERSION_1_8 -sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_6 +sourceCompatibility = JavaVersion.VERSION_1_6 dependencies { compile gradleApi() compile project(':processor') - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" compileOnly "com.android.tools.build:gradle:$androidToolsVersion" compileOnly "com.android.tools.build:gradle-api:$androidToolsVersion" From 376d88d8ff6335574375a54fd06b289dd596e42f Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 16:28:36 +0300 Subject: [PATCH 05/22] Obfuscate strings in nested classes Fixes #7 --- .../paranoid/processor/Analyzer.kt | 12 ++---- .../processor/CachedObfuscatedTypeRegistry.kt | 31 +++++++++++++++ .../processor/ObfuscatedTypeRegistry.kt | 23 +++++++++++ .../ObfuscatedTypeRegistryExtensions.kt | 35 +++++++++++++++++ .../processor/ObfuscatedTypeRegistryImpl.kt | 39 +++++++++++++++++++ 5 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 processor/src/main/kotlin/io/michaelrocks/paranoid/processor/CachedObfuscatedTypeRegistry.kt create mode 100644 processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistry.kt create mode 100644 processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryExtensions.kt create mode 100644 processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryImpl.kt diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Analyzer.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Analyzer.kt index 8b39c6b..a0f8bbf 100644 --- a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Analyzer.kt +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/Analyzer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2017 Michael Rozumyanskiy + * Copyright 2018 Michael Rozumyanskiy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package io.michaelrocks.paranoid.processor import io.michaelrocks.grip.Grip import io.michaelrocks.grip.and -import io.michaelrocks.grip.annotatedWith import io.michaelrocks.grip.classes import io.michaelrocks.grip.fields import io.michaelrocks.grip.from @@ -26,9 +25,7 @@ import io.michaelrocks.grip.isFinal import io.michaelrocks.grip.isStatic import io.michaelrocks.grip.mirrors.FieldMirror import io.michaelrocks.grip.mirrors.Type -import io.michaelrocks.grip.mirrors.getType import io.michaelrocks.grip.withFieldInitializer -import io.michaelrocks.paranoid.Obfuscate import java.io.File class Analyzer(private val grip: Grip) { @@ -42,7 +39,8 @@ class Analyzer(private val grip: Grip) { } private fun findTypesToObfuscate(inputs: List): Set { - val query = grip select classes from inputs where annotatedWith(OBFUSCATE_TYPE) + val registry = newObfuscatedTypeRegistry(grip.classRegistry).withCache() + val query = grip select classes from inputs where registry.shouldObfuscate() return query.execute().types.toHashSet() } @@ -60,8 +58,4 @@ class Analyzer(private val grip: Grip) { val query = grip select fields from mirror where (isStatic() and isFinal() and withFieldInitializer()) return query.execute()[type].orEmpty() } - - companion object { - private val OBFUSCATE_TYPE = getType() - } } diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/CachedObfuscatedTypeRegistry.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/CachedObfuscatedTypeRegistry.kt new file mode 100644 index 0000000..fd0643f --- /dev/null +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/CachedObfuscatedTypeRegistry.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2018 Michael Rozumyanskiy + * + * 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 io.michaelrocks.paranoid.processor + +import io.michaelrocks.grip.mirrors.Type + +class CachedObfuscatedTypeRegistry( + private val registry: ObfuscatedTypeRegistry +) : ObfuscatedTypeRegistry { + private val cache = mutableMapOf() + + override fun shouldObfuscate(type: Type.Object): Boolean { + return cache.getOrPut(type) { + registry.shouldObfuscate(type) + } + } +} diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistry.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistry.kt new file mode 100644 index 0000000..3d16577 --- /dev/null +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistry.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2018 Michael Rozumyanskiy + * + * 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 io.michaelrocks.paranoid.processor + +import io.michaelrocks.grip.mirrors.Type + +interface ObfuscatedTypeRegistry { + fun shouldObfuscate(type: Type.Object): Boolean +} diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryExtensions.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryExtensions.kt new file mode 100644 index 0000000..6f35b80 --- /dev/null +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryExtensions.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2018 Michael Rozumyanskiy + * + * 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 io.michaelrocks.paranoid.processor + +import io.michaelrocks.grip.ClassRegistry +import io.michaelrocks.grip.Grip +import io.michaelrocks.grip.mirrors.Type +import io.michaelrocks.grip.mirrors.Typed +import io.michaelrocks.grip.objectType + +fun newObfuscatedTypeRegistry(classRegistry: ClassRegistry): ObfuscatedTypeRegistry { + return ObfuscatedTypeRegistryImpl(classRegistry) +} + +fun ObfuscatedTypeRegistry.withCache(): ObfuscatedTypeRegistry { + return this as? CachedObfuscatedTypeRegistry ?: CachedObfuscatedTypeRegistry(this) +} + +fun ObfuscatedTypeRegistry.shouldObfuscate(): (Grip, Typed) -> Boolean { + return objectType { _, type -> shouldObfuscate(type) } +} diff --git a/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryImpl.kt b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryImpl.kt new file mode 100644 index 0000000..c891ff5 --- /dev/null +++ b/processor/src/main/kotlin/io/michaelrocks/paranoid/processor/ObfuscatedTypeRegistryImpl.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2018 Michael Rozumyanskiy + * + * 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 io.michaelrocks.paranoid.processor + +import io.michaelrocks.grip.ClassRegistry +import io.michaelrocks.grip.mirrors.Type +import io.michaelrocks.grip.mirrors.getObjectType +import io.michaelrocks.paranoid.Obfuscate + +class ObfuscatedTypeRegistryImpl( + private val classRegistry: ClassRegistry +) : ObfuscatedTypeRegistry { + override fun shouldObfuscate(type: Type.Object): Boolean { + val mirror = classRegistry.getClassMirror(type) + if (OBFUSCATE_TYPE in mirror.annotations) { + return true + } + + return mirror.enclosingType?.let { shouldObfuscate(it) } ?: false + } + + companion object { + private val OBFUSCATE_TYPE = getObjectType() + } +} From 65050539dbadc89eb17436b6e059916359940516 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 25 Feb 2018 16:29:33 +0300 Subject: [PATCH 06/22] Add nested classes with strings to obfuscate to the sample project #7 --- .../paranoid/sample/MainActivityTest.java | 2 ++ .../paranoid/sample/MainActivity.java | 25 +++++++++++++++++++ sample/src/main/res/layout/main_activity.xml | 5 ++++ 3 files changed, 32 insertions(+) diff --git a/sample/src/androidTest/java/io/michaelrocks/paranoid/sample/MainActivityTest.java b/sample/src/androidTest/java/io/michaelrocks/paranoid/sample/MainActivityTest.java index c5b0923..65d436c 100644 --- a/sample/src/androidTest/java/io/michaelrocks/paranoid/sample/MainActivityTest.java +++ b/sample/src/androidTest/java/io/michaelrocks/paranoid/sample/MainActivityTest.java @@ -42,5 +42,7 @@ public void textViewsHaveProperText() { .check(matches(withText("Q:\r\nHow does it work?"))); onView(withId(R.id.answerTextView)) .check(matches(withText("A:\r\nIt's magic! ¯\\_(ツ)_/¯"))); + onView(withId(R.id.showDialogButton)) + .check(matches(withText("Show dialog"))); } } diff --git a/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java b/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java index e89a47b..5d96330 100644 --- a/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java +++ b/sample/src/main/java/io/michaelrocks/paranoid/sample/MainActivity.java @@ -16,9 +16,14 @@ package io.michaelrocks.paranoid.sample; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; import android.widget.TextView; +import android.widget.Toast; import io.michaelrocks.paranoid.Obfuscate; @@ -37,5 +42,25 @@ protected void onCreate(final Bundle savedInstanceState) { final TextView answerTextView = findViewById(R.id.answerTextView); answerTextView.setText(String.format(ANSWER, "It's magic! ¯\\_(ツ)_/¯")); + + final Button showDialogButton = findViewById(R.id.showDialogButton); + showDialogButton.setText("Show dialog"); + showDialogButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View view) { + Toast.makeText(MainActivity.this, "Button clicked", Toast.LENGTH_SHORT).show(); + new AlertDialog.Builder(MainActivity.this) + .setTitle("Title") + .setMessage("Message 2") + .setPositiveButton("Close", new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + Toast.makeText(MainActivity.this, "Dialog dismissed", Toast.LENGTH_SHORT).show(); + dialog.dismiss(); + } + }) + .show(); + } + }); } } diff --git a/sample/src/main/res/layout/main_activity.xml b/sample/src/main/res/layout/main_activity.xml index bfa582c..d24ec82 100644 --- a/sample/src/main/res/layout/main_activity.xml +++ b/sample/src/main/res/layout/main_activity.xml @@ -21,4 +21,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> +