diff --git a/.gitignore b/.gitignore index 2ef4854..c9980bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ build/ local.properties *.iml classes/ +src/main/signKey/c/signKey.c +*.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 87da5ff..6c1690e 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,14 @@ #### [Plugin Obfuscation](https://github.com/StringCare/GradlePlugin/wiki/Plugin-Obfuscation) +#### [Compatibility](https://github.com/StringCare/GradlePlugin/wiki/Compatibility) + #### [Wiki Library](https://github.com/StringCare/AndroidLibrary/wiki) License ------- - Copyright 2018 StringCare [🐒 SpaceMonkeys] + Copyright 2019 StringCare [🐒 SpaceMonkeys] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/build.gradle b/build.gradle index ef1ea38..97cfdce 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,4 @@ -def siteUrl = 'https://github.com/StringCare/AndroidPlugin' -def gitUrl = 'https://github.com/StringCare/AndroidPlugin.git' - buildscript { repositories { mavenCentral() @@ -14,6 +11,9 @@ buildscript { } } +def siteUrl = 'https://github.com/StringCare/GradlePlugin' +def gitUrl = 'https://github.com/StringCare/GradlePlugin.git' + apply plugin: 'groovy' apply plugin: 'java' apply plugin: 'idea' @@ -34,12 +34,11 @@ repositories { } dependencies { - compile 'org.codehaus.groovy:groovy-all:2.4.12' + compile 'org.codehaus.groovy:groovy-all:2.5.4' compile gradleApi() testCompile 'org.spockframework:spock-core:1.0-groovy-2.4' } - install { repositories.mavenInstaller { pom { @@ -87,3 +86,7 @@ bintray { } } +processResources { + from 'src/main/groovy/jni' + include '*.dylib', '*.dll' +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2c2bbe5..0b430a8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip diff --git a/src/main/groovy/CredentialUtils.java b/src/main/groovy/CredentialUtils.java index f9ebffe..e471658 100644 --- a/src/main/groovy/CredentialUtils.java +++ b/src/main/groovy/CredentialUtils.java @@ -1,8 +1,5 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; public class CredentialUtils { diff --git a/src/main/groovy/FileUtils.java b/src/main/groovy/FileUtils.java index 957c16d..f3f1cc3 100644 --- a/src/main/groovy/FileUtils.java +++ b/src/main/groovy/FileUtils.java @@ -1,4 +1,6 @@ +import org.gradle.api.Project; + import java.io.*; public class FileUtils { @@ -37,8 +39,12 @@ public static String getTextFromFilePath(String path) { } private static String getCurrentPath(String module) { - File mod = new File(module); - return mod.exists() && mod.isDirectory() ? mod.getAbsolutePath() + File.separator : null; + if (OS.isWindows()) { + return System.getProperty("user.dir") + File.separator + module + File.separator; + } else { + File mod = new File(module); + return mod.exists() && mod.isDirectory() ? mod.getAbsolutePath() + File.separator : null; + } } public static String getString(BufferedReader br) { @@ -223,6 +229,11 @@ public static String find(String module, String xmlO, String key, boolean debug) String extra = " value_already_encrypted"; boolean hasExtra = false; + encrypted = jniObfuscate(key, result); + toShow = result; + content = content.replace(">" + result + "<", ">" + encrypted + "<"); + + /* if (isEncrypted(result, key)) { encrypted = result; toShow = AES.decrypt(result, key); @@ -231,7 +242,7 @@ public static String find(String module, String xmlO, String key, boolean debug) encrypted = AES.encrypt(result, key); toShow = result; content = content.replace(">" + result + "<", ">" + encrypted + "<"); - } + }*/ toShow = toShow.length() > maxToShow ? toShow.substring(0, maxToShow) + ".." : toShow; encrypted = encrypted.length() > maxToShow ? encrypted.substring(0, maxToShow) + ".." : encrypted; @@ -301,5 +312,41 @@ private static void copyFile(File source, File dest) throws IOException { } } + public static native String jniObfuscate(String key, String value); + + static { + try { + if (OS.isWindows()) { + loadLib("libsignKey.dll"); + } else { + loadLib("libsignKey.dylib"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * Loads library + * @param name Library name + * @throws IOException Exception + */ + private static void loadLib(String name) throws IOException { + InputStream in = FileUtils.class.getResourceAsStream(name); + byte[] buffer = new byte[1024]; + int read = -1; + File temp = File.createTempFile(name, ""); + FileOutputStream fos = new FileOutputStream(temp); + + while((read = in.read(buffer)) != -1) { + fos.write(buffer, 0, read); + } + fos.close(); + in.close(); + + System.load(temp.getAbsolutePath()); + } + } diff --git a/src/main/groovy/OS.java b/src/main/groovy/OS.java new file mode 100644 index 0000000..30b1d01 --- /dev/null +++ b/src/main/groovy/OS.java @@ -0,0 +1,16 @@ +public class OS { + + private static String OS = null; + + public static String getOsName() { + if (OS == null) { + OS = System.getProperty("os.name"); + } + return OS; + } + + public static boolean isWindows() { + return getOsName().toLowerCase().indexOf("win") > -1; + } + +} diff --git a/src/main/groovy/PrintUtils.java b/src/main/groovy/PrintUtils.java index 7cef6e6..e6a7105 100644 --- a/src/main/groovy/PrintUtils.java +++ b/src/main/groovy/PrintUtils.java @@ -1,8 +1,11 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PrintUtils { private static String variant; private static String module; + private static final Logger logger = LoggerFactory.getLogger(StringCare.class); private PrintUtils() { // nothing to do here @@ -24,24 +27,24 @@ public static void print(String message) { public static void print(String message, boolean tab) { if (variant != null && module != null) { if (!tab) { - System.out.println(":" + module + ":" + message); + _print(":" + module + ":" + message); } else { - System.out.println("\t" + message); + _print("\t" + message); } } else { - System.out.println(message); + _print(message); } } public static void print(String module, String message, boolean tab) { if (module != null) { if (!tab) { - System.out.println(":" + module + ":" + message); + _print(":" + module + ":" + message); } else { - System.out.println("\t" + message); + _print("\t" + message); } } else { - System.out.println(message); + _print(message); } } @@ -49,7 +52,9 @@ public static void print(String module, String message) { print(module, message, false); } - + private static void _print(String value) { + logger.info(value); + } public static String uncapitalize(String value) { return value.substring(0, 1).toLowerCase() + value.substring(1, value.length()); diff --git a/src/main/groovy/StringCarePlugin.groovy b/src/main/groovy/StringCarePlugin.groovy index ef847e0..715caa8 100644 --- a/src/main/groovy/StringCarePlugin.groovy +++ b/src/main/groovy/StringCarePlugin.groovy @@ -1,4 +1,3 @@ - import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.logging.Logger @@ -52,7 +51,7 @@ class StringCare implements Plugin { moduleMap.put(mod.name, config) } else if (mod.stringFiles != null) { List src = new ArrayList<>(); - src.add("src/main") + src.add("src" + File.separator + "main") config.setStringFiles(mod.stringFiles) config.setSrcFolders(src) moduleMap.put(mod.name, config) @@ -73,6 +72,7 @@ class StringCare implements Plugin { @Override void onMergeResourcesStarts(String module, String variant) { + key = CredentialUtils.getKey(module, variant, debug); if (!"none".equals(key) && key != null) { if (moduleMap.containsKey(module)) { @@ -81,13 +81,17 @@ class StringCare implements Plugin { FileUtils.backupStringResources(module, moduleMap.get(module), debug) PrintUtils.print(module, "encryptStringResources") - FileUtils.encryptStringResources(module, moduleMap.get(module), key, debug) + try { + FileUtils.encryptStringResources(module, moduleMap.get(module), key, debug) + } catch (Exception e) { + e.printStackTrace() + } } else { Config config = new Config(); List stg = new ArrayList<>(); stg.add("strings.xml") List src = new ArrayList<>(); - src.add("src/main") + src.add("src" + File.separator + "main") config.setStringFiles(stg) config.setSrcFolders(src) @@ -95,7 +99,11 @@ class StringCare implements Plugin { PrintUtils.print(module, "backupStringResources") FileUtils.backupStringResources(module, config, debug) PrintUtils.print(module, "encryptStringResources") - FileUtils.encryptStringResources(module, config, key, debug) + try { + FileUtils.encryptStringResources(module, config, key, debug) + } catch (Exception e) { + e.printStackTrace() + } } } @@ -103,7 +111,7 @@ class StringCare implements Plugin { @Override void onMergeResourcesFinish(String module, String variant) { - if (!"none".equals(key)&& key != null) { + if (!"none".equals(key) && key != null) { if (moduleMap.containsKey(module)) { PrintUtils.print(module, "restoreStringResources") FileUtils.restoreStringResources(module, moduleMap.get(module), debug) @@ -112,7 +120,7 @@ class StringCare implements Plugin { List stg = new ArrayList<>(); stg.add("strings.xml") List src = new ArrayList<>(); - src.add("src/main") + src.add("src" + File.separator + "main") config.setStringFiles(stg) config.setSrcFolders(src) @@ -125,7 +133,7 @@ class StringCare implements Plugin { } private void createExtensions() { - extension = project.extensions.create('stringcare', Extension ) + extension = project.extensions.create('stringcare', Extension) project.stringcare.extensions.modules = project.container(Conf) } } diff --git a/src/main/groovy/jni/libsignKey.dll b/src/main/groovy/jni/libsignKey.dll new file mode 100644 index 0000000..d54648b Binary files /dev/null and b/src/main/groovy/jni/libsignKey.dll differ diff --git a/src/main/groovy/jni/libsignKey.dylib b/src/main/groovy/jni/libsignKey.dylib new file mode 100755 index 0000000..d990ef8 Binary files /dev/null and b/src/main/groovy/jni/libsignKey.dylib differ