Skip to content

Commit 861fc76

Browse files
authored
Merge pull request #11 from StringCare/develop
Develop
2 parents bbb2c90 + 5858f9c commit 861fc76

File tree

11 files changed

+109
-29
lines changed

11 files changed

+109
-29
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ build/
55
local.properties
66
*.iml
77
classes/
8+
src/main/signKey/c/signKey.c
9+
*.DS_Store

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
#### [Plugin Obfuscation](https://github.com/StringCare/GradlePlugin/wiki/Plugin-Obfuscation)
1616

17+
#### [Compatibility](https://github.com/StringCare/GradlePlugin/wiki/Compatibility)
18+
1719
#### [Wiki Library](https://github.com/StringCare/AndroidLibrary/wiki)
1820

1921

2022
License
2123
-------
22-
Copyright 2018 StringCare [🐒 SpaceMonkeys]
24+
Copyright 2019 StringCare [🐒 SpaceMonkeys]
2325

2426
Licensed under the Apache License, Version 2.0 (the "License");
2527
you may not use this file except in compliance with the License.

build.gradle

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

2-
def siteUrl = 'https://github.com/StringCare/AndroidPlugin'
3-
def gitUrl = 'https://github.com/StringCare/AndroidPlugin.git'
4-
52
buildscript {
63
repositories {
74
mavenCentral()
@@ -14,6 +11,9 @@ buildscript {
1411
}
1512
}
1613

14+
def siteUrl = 'https://github.com/StringCare/GradlePlugin'
15+
def gitUrl = 'https://github.com/StringCare/GradlePlugin.git'
16+
1717
apply plugin: 'groovy'
1818
apply plugin: 'java'
1919
apply plugin: 'idea'
@@ -34,12 +34,11 @@ repositories {
3434
}
3535

3636
dependencies {
37-
compile 'org.codehaus.groovy:groovy-all:2.4.12'
37+
compile 'org.codehaus.groovy:groovy-all:2.5.4'
3838
compile gradleApi()
3939
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
4040
}
4141

42-
4342
install {
4443
repositories.mavenInstaller {
4544
pom {
@@ -87,3 +86,7 @@ bintray {
8786
}
8887
}
8988

89+
processResources {
90+
from 'src/main/groovy/jni'
91+
include '*.dylib', '*.dll'
92+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip

src/main/groovy/CredentialUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

2-
import java.io.BufferedReader;
3-
import java.io.IOException;
4-
import java.io.InputStream;
5-
import java.io.InputStreamReader;
2+
import java.io.*;
63

74
public class CredentialUtils {
85

src/main/groovy/FileUtils.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import org.gradle.api.Project;
3+
24
import java.io.*;
35

46
public class FileUtils {
@@ -37,8 +39,12 @@ public static String getTextFromFilePath(String path) {
3739
}
3840

3941
private static String getCurrentPath(String module) {
40-
File mod = new File(module);
41-
return mod.exists() && mod.isDirectory() ? mod.getAbsolutePath() + File.separator : null;
42+
if (OS.isWindows()) {
43+
return System.getProperty("user.dir") + File.separator + module + File.separator;
44+
} else {
45+
File mod = new File(module);
46+
return mod.exists() && mod.isDirectory() ? mod.getAbsolutePath() + File.separator : null;
47+
}
4248
}
4349

4450
public static String getString(BufferedReader br) {
@@ -223,6 +229,11 @@ public static String find(String module, String xmlO, String key, boolean debug)
223229
String extra = " value_already_encrypted";
224230
boolean hasExtra = false;
225231

232+
encrypted = jniObfuscate(key, result);
233+
toShow = result;
234+
content = content.replace(">" + result + "<", ">" + encrypted + "<");
235+
236+
/*
226237
if (isEncrypted(result, key)) {
227238
encrypted = result;
228239
toShow = AES.decrypt(result, key);
@@ -231,7 +242,7 @@ public static String find(String module, String xmlO, String key, boolean debug)
231242
encrypted = AES.encrypt(result, key);
232243
toShow = result;
233244
content = content.replace(">" + result + "<", ">" + encrypted + "<");
234-
}
245+
}*/
235246

236247
toShow = toShow.length() > maxToShow ? toShow.substring(0, maxToShow) + ".." : toShow;
237248
encrypted = encrypted.length() > maxToShow ? encrypted.substring(0, maxToShow) + ".." : encrypted;
@@ -301,5 +312,41 @@ private static void copyFile(File source, File dest) throws IOException {
301312
}
302313
}
303314

315+
public static native String jniObfuscate(String key, String value);
316+
317+
static {
318+
try {
319+
if (OS.isWindows()) {
320+
loadLib("libsignKey.dll");
321+
} else {
322+
loadLib("libsignKey.dylib");
323+
}
324+
} catch (Exception e) {
325+
e.printStackTrace();
326+
}
327+
}
328+
329+
330+
/**
331+
* Loads library
332+
* @param name Library name
333+
* @throws IOException Exception
334+
*/
335+
private static void loadLib(String name) throws IOException {
336+
InputStream in = FileUtils.class.getResourceAsStream(name);
337+
byte[] buffer = new byte[1024];
338+
int read = -1;
339+
File temp = File.createTempFile(name, "");
340+
FileOutputStream fos = new FileOutputStream(temp);
341+
342+
while((read = in.read(buffer)) != -1) {
343+
fos.write(buffer, 0, read);
344+
}
345+
fos.close();
346+
in.close();
347+
348+
System.load(temp.getAbsolutePath());
349+
}
350+
304351

305352
}

src/main/groovy/OS.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class OS {
2+
3+
private static String OS = null;
4+
5+
public static String getOsName() {
6+
if (OS == null) {
7+
OS = System.getProperty("os.name");
8+
}
9+
return OS;
10+
}
11+
12+
public static boolean isWindows() {
13+
return getOsName().toLowerCase().indexOf("win") > -1;
14+
}
15+
16+
}

src/main/groovy/PrintUtils.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import org.slf4j.Logger;
2+
import org.slf4j.LoggerFactory;
13

24
public class PrintUtils {
35

46
private static String variant;
57
private static String module;
8+
private static final Logger logger = LoggerFactory.getLogger(StringCare.class);
69

710
private PrintUtils() {
811
// nothing to do here
@@ -24,32 +27,34 @@ public static void print(String message) {
2427
public static void print(String message, boolean tab) {
2528
if (variant != null && module != null) {
2629
if (!tab) {
27-
System.out.println(":" + module + ":" + message);
30+
_print(":" + module + ":" + message);
2831
} else {
29-
System.out.println("\t" + message);
32+
_print("\t" + message);
3033
}
3134
} else {
32-
System.out.println(message);
35+
_print(message);
3336
}
3437
}
3538

3639
public static void print(String module, String message, boolean tab) {
3740
if (module != null) {
3841
if (!tab) {
39-
System.out.println(":" + module + ":" + message);
42+
_print(":" + module + ":" + message);
4043
} else {
41-
System.out.println("\t" + message);
44+
_print("\t" + message);
4245
}
4346
} else {
44-
System.out.println(message);
47+
_print(message);
4548
}
4649
}
4750

4851
public static void print(String module, String message) {
4952
print(module, message, false);
5053
}
5154

52-
55+
private static void _print(String value) {
56+
logger.info(value);
57+
}
5358

5459
public static String uncapitalize(String value) {
5560
return value.substring(0, 1).toLowerCase() + value.substring(1, value.length());

src/main/groovy/StringCarePlugin.groovy

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import org.gradle.api.Plugin
32
import org.gradle.api.Project
43
import org.gradle.api.logging.Logger
@@ -52,7 +51,7 @@ class StringCare implements Plugin<Project> {
5251
moduleMap.put(mod.name, config)
5352
} else if (mod.stringFiles != null) {
5453
List<String> src = new ArrayList<>();
55-
src.add("src/main")
54+
src.add("src" + File.separator + "main")
5655
config.setStringFiles(mod.stringFiles)
5756
config.setSrcFolders(src)
5857
moduleMap.put(mod.name, config)
@@ -73,6 +72,7 @@ class StringCare implements Plugin<Project> {
7372

7473
@Override
7574
void onMergeResourcesStarts(String module, String variant) {
75+
7676
key = CredentialUtils.getKey(module, variant, debug);
7777
if (!"none".equals(key) && key != null) {
7878
if (moduleMap.containsKey(module)) {
@@ -81,29 +81,37 @@ class StringCare implements Plugin<Project> {
8181
FileUtils.backupStringResources(module, moduleMap.get(module), debug)
8282
PrintUtils.print(module, "encryptStringResources")
8383

84-
FileUtils.encryptStringResources(module, moduleMap.get(module), key, debug)
84+
try {
85+
FileUtils.encryptStringResources(module, moduleMap.get(module), key, debug)
86+
} catch (Exception e) {
87+
e.printStackTrace()
88+
}
8589
} else {
8690
Config config = new Config();
8791
List<String> stg = new ArrayList<>();
8892
stg.add("strings.xml")
8993
List<String> src = new ArrayList<>();
90-
src.add("src/main")
94+
src.add("src" + File.separator + "main")
9195
config.setStringFiles(stg)
9296
config.setSrcFolders(src)
9397

9498
PrintUtils.print(module, variant + ":" + key)
9599
PrintUtils.print(module, "backupStringResources")
96100
FileUtils.backupStringResources(module, config, debug)
97101
PrintUtils.print(module, "encryptStringResources")
98-
FileUtils.encryptStringResources(module, config, key, debug)
102+
try {
103+
FileUtils.encryptStringResources(module, config, key, debug)
104+
} catch (Exception e) {
105+
e.printStackTrace()
106+
}
99107
}
100108
}
101109

102110
}
103111

104112
@Override
105113
void onMergeResourcesFinish(String module, String variant) {
106-
if (!"none".equals(key)&& key != null) {
114+
if (!"none".equals(key) && key != null) {
107115
if (moduleMap.containsKey(module)) {
108116
PrintUtils.print(module, "restoreStringResources")
109117
FileUtils.restoreStringResources(module, moduleMap.get(module), debug)
@@ -112,7 +120,7 @@ class StringCare implements Plugin<Project> {
112120
List<String> stg = new ArrayList<>();
113121
stg.add("strings.xml")
114122
List<String> src = new ArrayList<>();
115-
src.add("src/main")
123+
src.add("src" + File.separator + "main")
116124
config.setStringFiles(stg)
117125
config.setSrcFolders(src)
118126

@@ -125,7 +133,7 @@ class StringCare implements Plugin<Project> {
125133
}
126134

127135
private void createExtensions() {
128-
extension = project.extensions.create('stringcare', Extension )
136+
extension = project.extensions.create('stringcare', Extension)
129137
project.stringcare.extensions.modules = project.container(Conf)
130138
}
131139
}

src/main/groovy/jni/libsignKey.dll

3.67 MB
Binary file not shown.

0 commit comments

Comments
 (0)