Skip to content

Commit 19d7c57

Browse files
authored
Merge pull request #62 from StringCare/develop
Develop
2 parents fc942fb + 01088bb commit 19d7c57

File tree

17 files changed

+323
-32
lines changed

17 files changed

+323
-32
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
#### [Implementation](https://github.com/StringCare/AndroidLibrary/wiki/Implementation)
1212

13-
#### [Usage](https://github.com/StringCare/AndroidLibrary/wiki/Usage)
13+
#### [Strings Usage](https://github.com/StringCare/AndroidLibrary/wiki/Strings-Usage)
14+
15+
#### [Assets Usage](https://github.com/StringCare/AndroidLibrary/wiki/Assets-Usage)
1416

1517
#### [Configuration](https://github.com/StringCare/AndroidLibrary/wiki/Configuration)
1618

app/build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111

1212
defaultConfig {
1313
applicationId "com.efraespada.stringobfuscator"
14-
minSdkVersion 14
14+
minSdkVersion 15
1515
targetSdkVersion 28
1616
versionCode 1
1717
versionName "1.0"
@@ -55,9 +55,10 @@ dependencies {
5555
})
5656
implementation 'com.android.support:appcompat-v7:28.0.0'
5757
testImplementation 'junit:junit:4.12'
58-
// implementation project(path: ':library')
58+
implementation project(path: ':library')
5959
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
60-
implementation "com.stringcare:library:$stringcare_version"
60+
implementation 'commons-io:commons-io:2.5'
61+
// implementation "com.stringcare:library:$stringcare_version"
6162
}
6263

6364

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"user": "user123",
4+
"message": "hello world"
5+
},
6+
{
7+
"user": "user456",
8+
"message": "hello there"
9+
}
10+
]

app/src/main/assets/test.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"user": "user123",
3+
"message": "hello world"
4+
}

app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java

+9
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ protected void onCreate(Bundle savedInstanceState) {
4242
boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
4343
String areEquals = "Same result: " + equals;
4444
((TextView) findViewById(R.id.same_value)).setText(areEquals);
45+
46+
String jsonObjectName = SC.reveal(R.string.asset_json_file);
47+
SC.asset().asyncJson(jsonObjectName, json -> ((TextView) findViewById(R.id.json_object)).setText(json.toString()));
48+
SC.asset().asyncBytes(jsonObjectName, bytes -> ((TextView) findViewById(R.id.json_object_original)).setText(new String(bytes)), false);
49+
50+
String jsonArrayName = SC.reveal(R.string.asset_json_raw_file);
51+
SC.asset().asyncJsonArray(jsonArrayName, json -> ((TextView) findViewById(R.id.json_array)).setText(json.toString()));
52+
SC.asset().asyncBytes(jsonArrayName, bytes -> ((TextView) findViewById(R.id.json_array_original)).setText(new String(bytes)), false);
53+
4554
}
4655
}

app/src/main/res/layout/activity_main.xml

+64
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,70 @@
158158
app:androidTreatment="false"
159159
app:visible="true" />
160160

161+
<TextView
162+
android:layout_width="wrap_content"
163+
android:layout_height="wrap_content"
164+
android:layout_gravity="start"
165+
android:layout_marginTop="15dp"
166+
style="@style/TextAppearance.AppCompat.Title"
167+
android:text="@string/json_object_asset"
168+
android:padding="25dp"
169+
android:textColor="@android:color/black" />
170+
171+
<TextView
172+
android:id="@+id/json_object_original"
173+
android:layout_width="wrap_content"
174+
android:layout_height="wrap_content"
175+
android:layout_gravity="center_horizontal"
176+
android:layout_marginTop="15dp"
177+
android:paddingStart="25dp"
178+
android:paddingEnd="25dp"
179+
android:textSize="12sp"
180+
android:textColor="@android:color/darker_gray" />
181+
182+
<TextView
183+
android:id="@+id/json_object"
184+
android:layout_width="wrap_content"
185+
android:layout_height="wrap_content"
186+
android:layout_gravity="center_horizontal"
187+
android:layout_marginTop="15dp"
188+
android:paddingStart="25dp"
189+
android:paddingEnd="25dp"
190+
android:textColor="@android:color/black" />
191+
192+
<TextView
193+
android:layout_width="wrap_content"
194+
android:layout_height="wrap_content"
195+
android:layout_gravity="start"
196+
android:layout_marginTop="15dp"
197+
style="@style/TextAppearance.AppCompat.Title"
198+
android:text="@string/json_array_asset"
199+
android:padding="25dp"
200+
android:textColor="@android:color/black" />
201+
202+
<TextView
203+
android:id="@+id/json_array_original"
204+
android:layout_width="wrap_content"
205+
android:layout_height="wrap_content"
206+
android:layout_gravity="center_horizontal"
207+
android:layout_marginTop="15dp"
208+
android:paddingStart="25dp"
209+
android:paddingEnd="25dp"
210+
android:paddingBottom="25dp"
211+
android:textSize="12sp"
212+
android:textColor="@android:color/darker_gray" />
213+
214+
<TextView
215+
android:id="@+id/json_array"
216+
android:layout_width="wrap_content"
217+
android:layout_height="wrap_content"
218+
android:layout_gravity="center_horizontal"
219+
android:layout_marginTop="15dp"
220+
android:paddingStart="25dp"
221+
android:paddingEnd="25dp"
222+
android:paddingBottom="25dp"
223+
android:textColor="@android:color/black" />
224+
161225
</LinearLayout>
162226

163227
</ScrollView>

app/src/main/res/values/strings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
<string name="hello_world_c" hidden="true" androidTreatment="false">Hello
1717
World
1818
</string>
19+
<string name="asset_json_file" hidden="true">test.json</string>
20+
<string name="asset_json_raw_file" hidden="true">raw/test_array.json</string>
1921
<string name="long_new_line_comparison">Long New Line Comparison</string>
2022
<string name="html_treatment">HTML treatment</string>
2123
<string name="programmatically_obfuscation">Programmatically Obfuscation</string>
2224
<string name="patterns">Patterns</string>
2325
<string name="string_resource_disabling_android_treatment">String resource disabling Android treatment:</string>
26+
<string name="json_object_asset">JSON Asset</string>
27+
<string name="json_array_asset">JSON Array Raw Asset</string>
2428
</resources>

build.gradle

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ buildscript {
1616
}
1717

1818
dependencies {
19-
classpath "com.stringcare:plugin:$stringcare_version"
20-
// classpath files('../KotlinGradlePlugin/build/libs/plugin-3.1.jar')
21-
classpath 'com.android.tools.build:gradle:3.4.2'
19+
// classpath "com.stringcare:plugin:$stringcare_version"
20+
classpath files('../KotlinGradlePlugin/build/libs/plugin-3.3.jar')
21+
classpath 'com.android.tools.build:gradle:3.6.0-alpha06'
2222
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
2323
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
2424
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
@@ -44,10 +44,13 @@ apply plugin: StringCare
4444

4545
stringcare {
4646
debug true
47-
47+
modules {
48+
app {
49+
assetsFiles = ["*.json"]
50+
}
51+
}
4852
variants {
4953
prod {
50-
skip = true
5154
applicationId = "com.efraespada.stringobfuscator"
5255
}
5356
dev {
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat May 25 04:13:40 CEST 2019
1+
#Fri Aug 16 21:23:15 CEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip

library/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'com.github.dcendents.android-maven'
55
apply plugin: 'com.jfrog.bintray'
66

7-
version = "3.3"
7+
version = "3.4"
88

99
android {
1010
compileSdkVersion 28
1111
buildToolsVersion '28.0.3'
1212

1313
defaultConfig {
14-
minSdkVersion 14
14+
minSdkVersion 15
1515
targetSdkVersion 28
1616
versionCode 4
1717
versionName version
@@ -46,6 +46,7 @@ dependencies {
4646
exclude group: 'com.android.support', module: 'support-annotations'
4747
})
4848
implementation 'com.android.support:appcompat-v7:28.0.0'
49+
implementation 'org.jetbrains.anko:anko:0.10.8'
4950
implementation 'org.apache.commons:commons-lang3:3.9'
5051
testImplementation 'junit:junit:4.12'
5152
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.stringcare.library
2+
3+
interface AssetByteArrayListener : AssetListener {
4+
fun assetReady(byteArray: ByteArray)
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.stringcare.library
2+
3+
interface AssetListener

library/src/main/java/com/stringcare/library/CPlusLogic.kt

+50-19
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package com.stringcare.library
22

33
import android.content.Context
44
import android.content.res.Resources
5-
import android.os.Build
65
import android.support.annotation.StringRes
76
import java.nio.charset.Charset
8-
import java.util.*
7+
import kotlin.Exception
98

109
class CPlusLogic {
1110

@@ -75,8 +74,13 @@ class CPlusLogic {
7574
*/
7675
@JvmStatic
7776
fun revealV2(context: Context, @StringRes id: Int): String {
78-
val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray()
79-
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
77+
val value = context.getString(id)
78+
return try {
79+
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
80+
String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
81+
} catch (e: Exception) {
82+
value
83+
}
8084
}
8185

8286
/**
@@ -86,8 +90,12 @@ class CPlusLogic {
8690
*/
8791
@JvmStatic
8892
fun revealV2(context: Context, value: String): String {
89-
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
90-
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
93+
return try {
94+
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
95+
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
96+
} catch (e: Exception) {
97+
value
98+
}
9199
}
92100

93101
/**
@@ -125,11 +133,16 @@ class CPlusLogic {
125133
*/
126134
@JvmStatic
127135
fun revealV3(context: Context, @StringRes id: Int, androidTreatment: Boolean): String {
128-
val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray()
129-
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
130-
return when (androidTreatment) {
131-
true -> reveal.unescape()
132-
false -> reveal
136+
val value = context.getString(id)
137+
return try {
138+
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
139+
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
140+
when (androidTreatment) {
141+
true -> reveal.unescape()
142+
false -> reveal
143+
}
144+
} catch (e: Exception) {
145+
value
133146
}
134147
}
135148

@@ -140,14 +153,18 @@ class CPlusLogic {
140153
*/
141154
@JvmStatic
142155
fun revealV3(context: Context, value: String, androidTreatment: Boolean): String {
143-
val arr: ByteArray = when (androidTreatment) {
144-
true -> value.unescape()
145-
false -> value
146-
}.split(", ").map { it.toInt().toByte() }.toByteArray()
147-
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
148-
return when (androidTreatment) {
149-
true -> reveal.unescape()
150-
false -> reveal
156+
return try {
157+
val arr: ByteArray = when (androidTreatment) {
158+
true -> value.unescape()
159+
false -> value
160+
}.split(", ").map { it.toInt().toByte() }.toByteArray()
161+
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
162+
when (androidTreatment) {
163+
true -> reveal.unescape()
164+
false -> reveal
165+
}
166+
} catch (e: Exception) {
167+
value
151168
}
152169
}
153170

@@ -162,6 +179,20 @@ class CPlusLogic {
162179
return java.lang.String.format(Resources.getSystem().locale(), revealV3(context, id, androidTreatment), *formatArgs)
163180
}
164181

182+
/**
183+
* Reveals the given ByteArray
184+
* @param value
185+
* @return String
186+
*/
187+
@JvmStatic
188+
fun revealByteArray(context: Context, value: ByteArray): ByteArray {
189+
return try {
190+
SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), value)
191+
} catch (e: Exception) {
192+
value
193+
}
194+
}
195+
165196
}
166197

167198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.stringcare.library
2+
3+
import org.json.JSONArray
4+
5+
interface JSONArrayListener : AssetListener {
6+
fun assetReady(json: JSONArray)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.stringcare.library
2+
3+
import org.json.JSONObject
4+
5+
interface JSONObjectListener : AssetListener {
6+
fun assetReady(json: JSONObject)
7+
}

0 commit comments

Comments
 (0)