Skip to content

Commit

Permalink
Merge pull request #62 from StringCare/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
efraespada authored Aug 17, 2019
2 parents fc942fb + 01088bb commit 19d7c57
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 32 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

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

#### [Usage](https://github.com/StringCare/AndroidLibrary/wiki/Usage)
#### [Strings Usage](https://github.com/StringCare/AndroidLibrary/wiki/Strings-Usage)

#### [Assets Usage](https://github.com/StringCare/AndroidLibrary/wiki/Assets-Usage)

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

Expand Down
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {

defaultConfig {
applicationId "com.efraespada.stringobfuscator"
minSdkVersion 14
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -55,9 +55,10 @@ dependencies {
})
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
// implementation project(path: ':library')
implementation project(path: ':library')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.stringcare:library:$stringcare_version"
implementation 'commons-io:commons-io:2.5'
// implementation "com.stringcare:library:$stringcare_version"
}


10 changes: 10 additions & 0 deletions app/src/main/assets/raw/test_array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"user": "user123",
"message": "hello world"
},
{
"user": "user456",
"message": "hello there"
}
]
4 changes: 4 additions & 0 deletions app/src/main/assets/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"user": "user123",
"message": "hello world"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@ protected void onCreate(Bundle savedInstanceState) {
boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
String areEquals = "Same result: " + equals;
((TextView) findViewById(R.id.same_value)).setText(areEquals);

String jsonObjectName = SC.reveal(R.string.asset_json_file);
SC.asset().asyncJson(jsonObjectName, json -> ((TextView) findViewById(R.id.json_object)).setText(json.toString()));
SC.asset().asyncBytes(jsonObjectName, bytes -> ((TextView) findViewById(R.id.json_object_original)).setText(new String(bytes)), false);

String jsonArrayName = SC.reveal(R.string.asset_json_raw_file);
SC.asset().asyncJsonArray(jsonArrayName, json -> ((TextView) findViewById(R.id.json_array)).setText(json.toString()));
SC.asset().asyncBytes(jsonArrayName, bytes -> ((TextView) findViewById(R.id.json_array_original)).setText(new String(bytes)), false);

}
}
64 changes: 64 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,70 @@
app:androidTreatment="false"
app:visible="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="15dp"
style="@style/TextAppearance.AppCompat.Title"
android:text="@string/json_object_asset"
android:padding="25dp"
android:textColor="@android:color/black" />

<TextView
android:id="@+id/json_object_original"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:textSize="12sp"
android:textColor="@android:color/darker_gray" />

<TextView
android:id="@+id/json_object"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:textColor="@android:color/black" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="15dp"
style="@style/TextAppearance.AppCompat.Title"
android:text="@string/json_array_asset"
android:padding="25dp"
android:textColor="@android:color/black" />

<TextView
android:id="@+id/json_array_original"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:paddingBottom="25dp"
android:textSize="12sp"
android:textColor="@android:color/darker_gray" />

<TextView
android:id="@+id/json_array"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:paddingBottom="25dp"
android:textColor="@android:color/black" />

</LinearLayout>

</ScrollView>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
<string name="hello_world_c" hidden="true" androidTreatment="false">Hello
World
</string>
<string name="asset_json_file" hidden="true">test.json</string>
<string name="asset_json_raw_file" hidden="true">raw/test_array.json</string>
<string name="long_new_line_comparison">Long New Line Comparison</string>
<string name="html_treatment">HTML treatment</string>
<string name="programmatically_obfuscation">Programmatically Obfuscation</string>
<string name="patterns">Patterns</string>
<string name="string_resource_disabling_android_treatment">String resource disabling Android treatment:</string>
<string name="json_object_asset">JSON Asset</string>
<string name="json_array_asset">JSON Array Raw Asset</string>
</resources>
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ buildscript {
}

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

stringcare {
debug true

modules {
app {
assetsFiles = ["*.json"]
}
}
variants {
prod {
skip = true
applicationId = "com.efraespada.stringobfuscator"
}
dev {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat May 25 04:13:40 CEST 2019
#Fri Aug 16 21:23:15 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "3.3"
version = "3.4"

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 15
targetSdkVersion 28
versionCode 4
versionName version
Expand Down Expand Up @@ -46,6 +46,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'org.jetbrains.anko:anko:0.10.8'
implementation 'org.apache.commons:commons-lang3:3.9'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.stringcare.library

interface AssetByteArrayListener : AssetListener {
fun assetReady(byteArray: ByteArray)
}
3 changes: 3 additions & 0 deletions library/src/main/java/com/stringcare/library/AssetListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.stringcare.library

interface AssetListener
69 changes: 50 additions & 19 deletions library/src/main/java/com/stringcare/library/CPlusLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package com.stringcare.library

import android.content.Context
import android.content.res.Resources
import android.os.Build
import android.support.annotation.StringRes
import java.nio.charset.Charset
import java.util.*
import kotlin.Exception

class CPlusLogic {

Expand Down Expand Up @@ -75,8 +74,13 @@ class CPlusLogic {
*/
@JvmStatic
fun revealV2(context: Context, @StringRes id: Int): String {
val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray()
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
val value = context.getString(id)
return try {
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
} catch (e: Exception) {
value
}
}

/**
Expand All @@ -86,8 +90,12 @@ class CPlusLogic {
*/
@JvmStatic
fun revealV2(context: Context, value: String): String {
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
return try {
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
} catch (e: Exception) {
value
}
}

/**
Expand Down Expand Up @@ -125,11 +133,16 @@ class CPlusLogic {
*/
@JvmStatic
fun revealV3(context: Context, @StringRes id: Int, androidTreatment: Boolean): String {
val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray()
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
return when (androidTreatment) {
true -> reveal.unescape()
false -> reveal
val value = context.getString(id)
return try {
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
when (androidTreatment) {
true -> reveal.unescape()
false -> reveal
}
} catch (e: Exception) {
value
}
}

Expand All @@ -140,14 +153,18 @@ class CPlusLogic {
*/
@JvmStatic
fun revealV3(context: Context, value: String, androidTreatment: Boolean): String {
val arr: ByteArray = when (androidTreatment) {
true -> value.unescape()
false -> value
}.split(", ").map { it.toInt().toByte() }.toByteArray()
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
return when (androidTreatment) {
true -> reveal.unescape()
false -> reveal
return try {
val arr: ByteArray = when (androidTreatment) {
true -> value.unescape()
false -> value
}.split(", ").map { it.toInt().toByte() }.toByteArray()
val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr))
when (androidTreatment) {
true -> reveal.unescape()
false -> reveal
}
} catch (e: Exception) {
value
}
}

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

/**
* Reveals the given ByteArray
* @param value
* @return String
*/
@JvmStatic
fun revealByteArray(context: Context, value: ByteArray): ByteArray {
return try {
SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), value)
} catch (e: Exception) {
value
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.stringcare.library

import org.json.JSONArray

interface JSONArrayListener : AssetListener {
fun assetReady(json: JSONArray)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.stringcare.library

import org.json.JSONObject

interface JSONObjectListener : AssetListener {
fun assetReady(json: JSONObject)
}
Loading

0 comments on commit 19d7c57

Please sign in to comment.