Skip to content

Commit bb152b2

Browse files
committed
testing fingerprint detection
1 parent a390cee commit bb152b2

File tree

7 files changed

+88
-76
lines changed

7 files changed

+88
-76
lines changed

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Android String Obfuscator
33

44
Hide strings easyly with that lib! It uses AES/ECB/PKCS5Padding transformation to convert strings with your app's SHA1 fingerprint.
55

6-
Note that there is a difference between release and debug fingerprint.
7-
86
Installation
97
------------
108

@@ -22,33 +20,30 @@ dependencies {
2220
}
2321
2422
android.applicationVariants.all{ variant ->
23+
2524
variant.mergeResources.doLast{
26-
println ":" + project.name + ":stringObfuscation"
27-
def sha1 = ""
28-
if (variant.dirName == "release") sha1 = "SHA1_fingerprint_RELEASE"
29-
else sha1 = "SHA1_fingerprint_DEBUG"
30-
def sha1_ = sha1.replaceAll(":","")
31-
def path = "build" + File.separator + "intermediates" + File.separator + "res" + File.separator + "merged" + File.separator + "${variant.dirName}" + File.separator + "values" + File.separator + "values.xml"
25+
26+
println ":" + project.name + ":initStringObfuscator"
27+
def path = "build" + File.separator + "intermediates" + File.separator + "res" + File.separator + "merged" + File.separator + variant.dirName + File.separator + "values" + File.separator + "values.xml"
3228
def stringsFile = file(path)
3329
if (stringsFile.isFile()) {
3430
javaexec {
3531
main = "-jar";
3632
args = [
3733
"AndroidStringObfuscator.jar",
3834
path,
39-
sha1
35+
variant.dirName,
36+
project.name
4037
]
4138
}
42-
def stringsFileObfus = file(sha1_ + "/strings.xml")
39+
def stringsFileObfus = file("string_obfuscation/strings.xml")
4340
stringsFile.write(stringsFileObfus.getText('UTF-8'))
4441
stringsFileObfus.delete()
4542
} else logger.error("strings.xml file couldn't be found: " + path)
4643
}
4744
}
4845
```
4946

50-
Replace `sha1` variable with your SHA1 fingerprint. Use `AndroidStringObfuscator.getCertificateSHA1Fingerprint(Context)` method to obtain this value.
51-
5247

5348
Get encrypted strings
5449
---------------------
@@ -69,12 +64,6 @@ String decrypted = AndroidStringObfuscator.getString(context, R.string.app_name)
6964
```
7065

7166

72-
Get SHA1 fingerprint
73-
--------------------
74-
```java
75-
String SHA1_fingerprint = AndroidStringObfuscator.getCertificateSHA1Fingerprint(context);
76-
```
77-
7867
License
7968
-------
8069
Copyright 2016 Efraín Espada
0 Bytes
Binary file not shown.

local.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Location of the SDK. This is only used by Gradle.
88
# For customization when using a Version Control System, please read the
99
# header note.
10-
#Tue Dec 27 01:21:22 CET 2016
10+
#Fri Jan 20 22:45:57 CET 2017
1111
bintrayUser=efff
1212
bintrayApiKey=1acf1ed062001f9a372e2391fdd0c16aed54a88a
1313
sdk.dir=/Users/efrainespada/Library/Android/sdk

obfuscator-script/src/main/Core.java

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
public class Core {
1818

1919
static BufferedWriter writer = null;
20+
static String key = null;
2021
static String module = null;
2122
static String variant = null;
23+
static boolean variantLocated = false;
2224

23-
final String TAG = "obfuscator-script";
25+
final static String TAG = "obfuscator-script";
26+
final static String SEPARATOR = "-----------------------------------------------------------------------------";
27+
final static String VERSION = "0.4";
28+
final static int maxToShow = 15;
29+
final static String FOLDER = "string_obfuscation";
2430

2531
public static void main(String[] args) {
26-
27-
String xml = "";
28-
System.out.println(":obfuscator-script: -----------------------------------------------------------------------------");
29-
System.out.println(":obfuscator-script: v0.4 --- bugs or improvements to https://github.com/efraespada/AndroidStringObfuscator/issues");
30-
System.out.println(":obfuscator-script: -----------------------------------------------------------------------------");
3132

3233
if (args.length != 3) {
33-
System.out.println(":obfuscator-script: -> params [xml_file_name] [variant] [module]");
34+
print("-> params [xml_file_name] [variant] [module]");
3435
System.exit(0);
3536
return;
3637
}
@@ -46,12 +47,15 @@ else if (i == 2)
4647
module = args[i];
4748
}
4849

49-
String key = getKey(variant, module);
50+
String xml = "";
51+
print(SEPARATOR);
52+
53+
getKey();
5054

5155
File jarFile = new File(".");
5256

5357
String inputFilePath = jarFile.getAbsolutePath().replace(".", "") + file;
54-
System.out.println(":obfuscator-script: -> looking for string file on -> " + inputFilePath);
58+
print("looking for string file on -> " + inputFilePath);
5559
String message = "";
5660
try {
5761
FileInputStream stream = new FileInputStream(new File(inputFilePath));
@@ -65,10 +69,8 @@ else if (i == 2)
6569
}
6670

6771
xml = find(message, key);
68-
69-
String folderName = key.replaceAll(":", "");
7072

71-
File fingerFolder = new File(folderName);
73+
File fingerFolder = new File(FOLDER);
7274
if (!fingerFolder.exists()) {
7375
try {
7476
Files.createDirectory(fingerFolder.toPath());
@@ -79,7 +81,10 @@ else if (i == 2)
7981

8082
File xmlFile = new File(fingerFolder, "strings.xml");
8183
writeFile(xmlFile, xml);
82-
System.out.println(":obfuscator-script: -----------------------------------------------------------------------------");
84+
85+
print(SEPARATOR);
86+
print("v" + VERSION + " --- bugs or improvements to https://github.com/efraespada/AndroidStringObfuscator/issues");
87+
print(SEPARATOR);
8388
}
8489

8590
public static String getString(BufferedReader br) {
@@ -148,11 +153,11 @@ public static String find(String xmlO, String key) {
148153
}
149154

150155

151-
toShow = toShow.length() > 8 ? toShow.substring(0, 8) + ".." : toShow;
152-
encrypted = encrypted.length() > 8 ? encrypted.substring(0, 8) + ".." : encrypted;
153-
System.out.println(":obfuscator-script: -> [" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""));
156+
toShow = toShow.length() > maxToShow ? toShow.substring(0, maxToShow) + ".." : toShow;
157+
encrypted = encrypted.length() > maxToShow ? encrypted.substring(0, maxToShow) + ".." : encrypted;
158+
print("[" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""));
154159
} catch (Exception e) {
155-
System.out.println("error on " + result);
160+
print("error on " + result);
156161
e.printStackTrace();
157162
}
158163

@@ -171,9 +176,7 @@ public static String extrac(String val) {
171176
return val;
172177
}
173178

174-
public static String getKey(String variant, String module) {
175-
String key = null;
176-
179+
public static void getKey() {
177180
try {
178181

179182
String cmd = "";
@@ -189,43 +192,66 @@ public static String getKey(String variant, String module) {
189192
BufferedReader buff = new BufferedReader (isr);
190193

191194
String line;
192-
String trace = "";
193-
ArrayList<String> traces = new ArrayList<>()
194-
while((line = buff.readLine()) != null) {
195-
boolean result = parseTrace(module, variant, line);
195+
while ((line = buff.readLine()) != null) {
196+
parseTrace(line);
196197

197-
traces.add(e)
198-
trace += line + "\n";
199-
System.out.println(line);
198+
if (key != null) {
199+
print("SHA1 fingerprint: " + key);
200+
break;
201+
}
202+
200203
}
201204

202-
System.out.println(trace);
203-
} catch (IOException e2) {
204-
e2.printStackTrace();
205-
return null;
205+
} catch (IOException e) {
206+
e.printStackTrace();
206207
}
207-
208-
return key;
209208
}
210209

211210
/**
212-
* returns true if
211+
* returns true if key has been located
213212
* @param moduleName
214-
* @param traces
215213
* @param variant
214+
* @param line
216215
* @return boolean
217216
*/
218-
public static boolean parseTrace(String moduleName, String variant, String line) {
217+
public static void parseTrace(String line) {
218+
219+
boolean mustPrint = false;
219220

220-
return false;
221+
if (line.toLowerCase().contains("downloading")) {
222+
mustPrint = true;
223+
} else if (line.toLowerCase().contains("unzipping")) {
224+
mustPrint = true;
225+
} else if (line.toLowerCase().contains("permissions")) {
226+
mustPrint = true;
227+
} else if (line.toLowerCase().contains("sha")) {
228+
if (variantLocated)
229+
key = line.split(" ")[1];
230+
231+
} else if (line.toLowerCase().contains("variant")) {
232+
String locV = line.split(" ")[1];
233+
if (locV.equals(variant)) {
234+
print(locV + " variant");
235+
variantLocated = true;
236+
}
237+
}
238+
239+
if (mustPrint)
240+
print(line);
221241
}
222242

223-
private static void print() {
224-
String var = ":undefined";
243+
/**
244+
* prints messages (for gradle console)
245+
* @param message
246+
*/
247+
private static void print(String message) {
248+
String var = ":undefined:";
225249

226250
if (variant != null)
227-
var = variant;
251+
var = ":" + module + ":";
252+
253+
var += TAG;
228254

229-
var += ""
255+
System.out.println(var + " - " + message);
230256
}
231257
}

sample/AndroidStringObfuscator.jar

754 Bytes
Binary file not shown.

sample/build.gradle

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,20 @@ android.applicationVariants.all{ variant ->
4747

4848
variant.mergeResources.doLast{
4949

50-
println ":" + project.name + ":stringObfuscation"
51-
def sha1 = ""
52-
if (variant.dirName == "release") sha1 = "E1:28:0C:3E:65:96:2E:21:E9:98:2B:58:80:9A:25:3A:F6:88:7D:FF"
53-
else sha1 = "E1:28:0C:3E:65:96:2E:21:E9:98:2B:58:80:9A:25:3A:F6:88:7D:FF"
54-
def sha1_ = sha1.replaceAll(":","")
55-
def path = "build" + File.separator + "intermediates" + File.separator + "res" + File.separator + "merged" + File.separator + "${variant.dirName}" + File.separator + "values" + File.separator + "values.xml"
50+
println ":" + project.name + ":initStringObfuscator"
51+
def path = "build" + File.separator + "intermediates" + File.separator + "res" + File.separator + "merged" + File.separator + variant.dirName + File.separator + "values" + File.separator + "values.xml"
5652
def stringsFile = file(path)
5753
if (stringsFile.isFile()) {
5854
javaexec {
5955
main = "-jar";
6056
args = [
6157
"AndroidStringObfuscator.jar",
6258
path,
63-
sha1
59+
variant.dirName,
60+
project.name
6461
]
6562
}
66-
def stringsFileObfus = file(sha1_ + "/strings.xml")
63+
def stringsFileObfus = file("string_obfuscation/strings.xml")
6764
stringsFile.write(stringsFileObfus.getText('UTF-8'))
6865
stringsFileObfus.delete()
6966
} else logger.error("strings.xml file couldn't be found: " + path)

sample/sample.iml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6868
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
76-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
7971
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
@@ -82,6 +74,14 @@
8274
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
8375
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
8476
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
84+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
8787
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />

0 commit comments

Comments
 (0)