Skip to content

Commit 8540fcd

Browse files
authored
Merge pull request #53 from StringCare/develop
Develop
2 parents 8d6f2b7 + 03fab48 commit 8540fcd

File tree

20 files changed

+526
-359
lines changed

20 files changed

+526
-359
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#### [Compatibility](https://github.com/StringCare/AndroidLibrary/wiki/Compatibility)
2222

23-
#### [Migrate From 0.x To 1.x](https://github.com/StringCare/AndroidLibrary/wiki/Migrate-From-0.x-To-1.x)
23+
#### [Migrations](https://github.com/StringCare/AndroidLibrary/wiki/Migrations)
2424

2525
[link]: https://github.com/StringCare/AndroidLibrary
2626
[badge]: https://img.shields.io/bintray/v/efff/maven/StringCareAndroidPlugin.svg

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android-extensions'
3+
apply plugin: 'kotlin-android'
24

35
android {
46
signingConfigs {
@@ -39,6 +41,7 @@ dependencies {
3941
implementation 'com.android.support:appcompat-v7:28.0.0'
4042
testImplementation 'junit:junit:4.12'
4143
// implementation project(path: ':library')
44+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4245
implementation "com.stringcare:library:$stringcare_version"
4346
}
4447

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
5-
import android.text.Html;
5+
import android.util.Log;
66
import android.view.View;
77
import android.widget.TextView;
88

99
import com.stringcare.library.SC;
1010
import com.stringcare.library.SCTextView;
11+
import com.stringcare.library.Version;
1112

1213
public class MainActivity extends AppCompatActivity {
1314

@@ -18,16 +19,22 @@ protected void onCreate(Bundle savedInstanceState) {
1819

1920
SC.init(getApplicationContext());
2021

22+
// 108, 97, 108, 105, 108, 117, 108, 101, 108, 111, 10, 104, 111, 108, 105 works
23+
// 108, 97, 108, 105, 108, 117, 108, 101, 108, 111, 92, 110, 104, 111, 108, 105 not works
24+
2125
// secret var
22-
String password = "lalilulelo";
26+
String password = getString(R.string.snake);
27+
String original = SC.reveal(R.string.snake, Version.V2);
2328

24-
String message = "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " + SC.obfuscate(password)
25-
+ "\n\n.. or " + SC.reveal(SC.obfuscate(password)) + "\"";
29+
String message = "Snake, the password is " + password + original;
2630

27-
((TextView) findViewById(R.id.example_a)).setText(Html.fromHtml(message));
31+
((TextView) findViewById(R.id.example_a)).setText(message);
2832

2933
String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.reveal(R.string.test_a, "hi", 3);
3034
((TextView) findViewById(R.id.example_b)).setText(numbers);
35+
36+
Log.e("test", String.valueOf(getString(R.string.snake2).equals(SC.reveal(R.string.snake))));
37+
3138
final SCTextView tvAuto = findViewById(R.id.auto_tv);
3239
findViewById(R.id.btn_change).setOnClickListener(new View.OnClickListener() {
3340
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@
6363

6464
</ScrollView>
6565

66-
</LinearLayout>
66+
</LinearLayout>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<resources>
23
<string name="app_name">String Obfuscator Sample</string>
34
<string name="hello" hidden="true">
4-
<br><b>Hello <i>Mr O'Callaghan</i></b>
5-
<br>No, I'm talking with my father.
6-
<br>Yes yes, but <strong>take it easy</strong>.<br>
5+
<br><i>Hello there</i>
6+
<br>General <strong>Kenobi</strong>.<br>
77
</string>
88
<string name="test_a" hidden="true">%1$s (%2$d)</string>
9+
<string name="snake" hidden="true">\n\nla-li-lu-le-lo\n\n🐍😄🍉</string>
10+
<string name="snake2">\n\nla-li-lu-le-lo\n\n🐍😄🍉</string>
911
</resources>

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
buildscript {
3+
ext.kotlin_version = '1.3.31'
34

45
ext {
5-
stringcare_version = '1.6'
6+
stringcare_version = '2.1'
67
}
78

89
repositories {
@@ -16,11 +17,12 @@ buildscript {
1617

1718
dependencies {
1819
classpath "com.stringcare:plugin:$stringcare_version"
19-
// classpath files('../GradlePlugin/build/libs/plugin-1.5.jar')
20+
// classpath files('../GradlePlugin/build/libs/plugin-2.0.jar')
2021
// classpath files('..\\GradlePlugin\\build\\libs\\plugin-0.9.jar')
2122
classpath 'com.android.tools.build:gradle:3.4.1'
2223
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
2324
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
25+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2426
}
2527
}
2628

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Tue May 07 22:19:17 CEST 2019
1+
#Sat May 25 04:13:40 CEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

library/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Sets the minimum version of CMake required to build the native library.
55

6-
cmake_minimum_required(VERSION 3.10.2)
6+
cmake_minimum_required(VERSION 3.14.4)
77

88
# Creates and names a library, sets it as either STATIC
99
# or SHARED, and provides the relative paths to its source code.

library/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android-extensions'
3+
apply plugin: 'kotlin-android'
24
apply plugin: 'com.github.dcendents.android-maven'
35
apply plugin: 'com.jfrog.bintray'
46

5-
version = "1.6"
7+
version = "2.1"
68

79
android {
810
compileSdkVersion 28
@@ -32,7 +34,7 @@ android {
3234
}
3335
externalNativeBuild {
3436
cmake {
35-
version "3.14.3"
37+
version "3.14.4"
3638
path "CMakeLists.txt"
3739
}
3840
}
@@ -45,6 +47,7 @@ dependencies {
4547
})
4648
implementation 'com.android.support:appcompat-v7:28.0.0'
4749
testImplementation 'junit:junit:4.12'
50+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4851
}
4952

5053
def siteUrl = 'https://github.com/StringCare/AndroidLibrary'
@@ -91,6 +94,7 @@ task sourcesJar(type: Jar) {
9194

9295
task javadoc(type: Javadoc) {
9396
exclude '**/**.java'
97+
exclude '**/**.kt'
9498
source = android.sourceSets.main.java.srcDirs
9599
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
96100
}
@@ -119,4 +123,7 @@ bintray {
119123
licenses = ["Apache-2.0"]
120124
publish = true
121125
}
126+
}
127+
repositories {
128+
mavenCentral()
122129
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package com.stringcare.library
2+
3+
import android.content.Context
4+
import android.content.res.Resources
5+
import android.os.Build
6+
import android.support.annotation.StringRes
7+
import java.nio.charset.Charset
8+
import java.util.*
9+
10+
class CPlusLogic {
11+
12+
companion object {
13+
14+
/**
15+
* Obfuscates the given value
16+
* @param value
17+
* @return String
18+
*/
19+
@JvmStatic
20+
fun obfuscateV1(context: Context, value: String): String? {
21+
return SC().jniObfuscateV1(context, getCertificateSHA1Fingerprint(context), value)
22+
}
23+
24+
/**
25+
* Reveals the given value
26+
* @param id
27+
* @return String
28+
*/
29+
@JvmStatic
30+
fun revealV1(context: Context, @StringRes id: Int): String? {
31+
return SC().jniRevealV1(context, getCertificateSHA1Fingerprint(context), context.getString(id))
32+
}
33+
34+
/**
35+
* Reveals the given value
36+
* @param value
37+
* @return String
38+
*/
39+
@JvmStatic
40+
fun revealV1(context: Context, value: String): String? {
41+
return SC().jniRevealV1(context, getCertificateSHA1Fingerprint(context), value)
42+
}
43+
44+
/**
45+
* Reveals the given value
46+
* @param id
47+
* @param formatArgs
48+
* @return
49+
*/
50+
@JvmStatic
51+
fun revealV1(context: Context, @StringRes id: Int, formatArgs: Array<out Any>): String ? {
52+
val value = revealV1(context, id)
53+
value?.let {
54+
val locale: Locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
55+
Resources.getSystem().configuration.locales.get(0)
56+
} else {
57+
Resources.getSystem().configuration.locale
58+
}
59+
return java.lang.String.format(locale, it, *formatArgs)
60+
}
61+
return null
62+
}
63+
64+
/**
65+
* Obfuscates the given value
66+
* @param value
67+
* @return String
68+
*/
69+
@JvmStatic
70+
fun obfuscateV2(context: Context, value: String): String? {
71+
val bytes = Charset.forName("UTF-8").encode(value)
72+
val arrO = ByteArray(bytes.remaining())
73+
bytes.get(arrO)
74+
val arr: ByteArray = SC().jniObfuscateV2(context, getCertificateSHA1Fingerprint(context), arrO)
75+
return arr.map { it.toInt() }.toString().replace("[","").replace("]","")
76+
}
77+
78+
/**
79+
* Reveals the given value
80+
* @param id
81+
* @return String
82+
*/
83+
@JvmStatic
84+
fun revealV2(context: Context, @StringRes id: Int): String? {
85+
val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray()
86+
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
87+
}
88+
89+
/**
90+
* Reveals the given value
91+
* @param value
92+
* @return String
93+
*/
94+
@JvmStatic
95+
fun revealV2(context: Context, value: String): String? {
96+
val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray()
97+
return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
98+
}
99+
100+
/**
101+
* Reveals the given value
102+
* @param id
103+
* @param formatArgs
104+
* @return
105+
*/
106+
@JvmStatic
107+
fun revealV2(context: Context, @StringRes id: Int, formatArgs: Array<out Any>): String? {
108+
val value = revealV2(context, id)
109+
value?.let {
110+
val locale: Locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
111+
Resources.getSystem().configuration.locales.get(0)
112+
} else {
113+
Resources.getSystem().configuration.locale
114+
}
115+
return java.lang.String.format(locale, it, *formatArgs)
116+
}
117+
return null
118+
}
119+
120+
}
121+
122+
}

library/src/main/java/com/stringcare/library/ContextListener.java

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.stringcare.library
2+
3+
interface ContextListener {
4+
5+
fun contextReady()
6+
7+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.stringcare.library
2+
3+
import android.content.Context
4+
import android.content.pm.PackageInfo
5+
import android.content.pm.PackageManager
6+
import java.io.ByteArrayInputStream
7+
import java.io.UnsupportedEncodingException
8+
import java.security.MessageDigest
9+
import java.security.NoSuchAlgorithmException
10+
import java.security.cert.CertificateEncodingException
11+
import java.security.cert.CertificateException
12+
import java.security.cert.CertificateFactory
13+
import java.security.cert.X509Certificate
14+
import java.util.*
15+
import javax.crypto.SecretKey
16+
import javax.crypto.spec.SecretKeySpec
17+
18+
internal fun getCertificateSHA1Fingerprint(context: Context): String? {
19+
val pm = context.packageManager
20+
val flags = PackageManager.GET_SIGNATURES
21+
var packageInfo: PackageInfo? = null
22+
try {
23+
packageInfo = pm.getPackageInfo(context.packageName, flags)
24+
} catch (e: PackageManager.NameNotFoundException) {
25+
e.printStackTrace()
26+
}
27+
28+
val signatures = packageInfo!!.signatures
29+
val cert = signatures[0].toByteArray()
30+
val input = ByteArrayInputStream(cert)
31+
var cf: CertificateFactory? = null
32+
try {
33+
cf = CertificateFactory.getInstance("X509")
34+
} catch (e: CertificateException) {
35+
e.printStackTrace()
36+
}
37+
38+
var c: X509Certificate? = null
39+
try {
40+
c = cf!!.generateCertificate(input) as X509Certificate
41+
} catch (e: CertificateException) {
42+
e.printStackTrace()
43+
}
44+
45+
var hexString: String? = null
46+
try {
47+
val md = MessageDigest.getInstance("SHA1")
48+
val publicKey = md.digest(c!!.encoded)
49+
hexString = publicKey.asHexUpper
50+
} catch (e1: NoSuchAlgorithmException) {
51+
e1.printStackTrace()
52+
} catch (e1: CertificateEncodingException) {
53+
e1.printStackTrace()
54+
}
55+
56+
return hexString
57+
}
58+
59+
@Throws(NoSuchAlgorithmException::class)
60+
internal fun generateKey(key: String): SecretKey {
61+
val digest = MessageDigest.getInstance("SHA-1")
62+
var passphrase: ByteArray? = null
63+
try {
64+
passphrase = digest.digest(key.toByteArray(charset(codification)))
65+
} catch (e: UnsupportedEncodingException) {
66+
e.printStackTrace()
67+
}
68+
69+
passphrase = Arrays.copyOf(passphrase!!, 16)
70+
return SecretKeySpec(passphrase, "AES")
71+
}

0 commit comments

Comments
 (0)