Skip to content

Commit

Permalink
Merge pull request #11 from StringCare/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
efraespada authored Jan 15, 2019
2 parents bbb2c90 + 5858f9c commit 861fc76
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ build/
local.properties
*.iml
classes/
src/main/signKey/c/signKey.c
*.DS_Store
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

def siteUrl = 'https://github.com/StringCare/AndroidPlugin'
def gitUrl = 'https://github.com/StringCare/AndroidPlugin.git'

buildscript {
repositories {
mavenCentral()
Expand All @@ -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'
Expand All @@ -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 {
Expand Down Expand Up @@ -87,3 +86,7 @@ bintray {
}
}

processResources {
from 'src/main/groovy/jni'
include '*.dylib', '*.dll'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/main/groovy/CredentialUtils.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
53 changes: 50 additions & 3 deletions src/main/groovy/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import org.gradle.api.Project;

import java.io.*;

public class FileUtils {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}


}
16 changes: 16 additions & 0 deletions src/main/groovy/OS.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
19 changes: 12 additions & 7 deletions src/main/groovy/PrintUtils.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,32 +27,34 @@ 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);
}
}

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());
Expand Down
24 changes: 16 additions & 8 deletions src/main/groovy/StringCarePlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger
Expand Down Expand Up @@ -52,7 +51,7 @@ class StringCare implements Plugin<Project> {
moduleMap.put(mod.name, config)
} else if (mod.stringFiles != null) {
List<String> 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)
Expand All @@ -73,6 +72,7 @@ class StringCare implements Plugin<Project> {

@Override
void onMergeResourcesStarts(String module, String variant) {

key = CredentialUtils.getKey(module, variant, debug);
if (!"none".equals(key) && key != null) {
if (moduleMap.containsKey(module)) {
Expand All @@ -81,29 +81,37 @@ class StringCare implements Plugin<Project> {
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<String> stg = new ArrayList<>();
stg.add("strings.xml")
List<String> src = new ArrayList<>();
src.add("src/main")
src.add("src" + File.separator + "main")
config.setStringFiles(stg)
config.setSrcFolders(src)

PrintUtils.print(module, variant + ":" + key)
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()
}
}
}

}

@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)
Expand All @@ -112,7 +120,7 @@ class StringCare implements Plugin<Project> {
List<String> stg = new ArrayList<>();
stg.add("strings.xml")
List<String> src = new ArrayList<>();
src.add("src/main")
src.add("src" + File.separator + "main")
config.setStringFiles(stg)
config.setSrcFolders(src)

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

private void createExtensions() {
extension = project.extensions.create('stringcare', Extension )
extension = project.extensions.create('stringcare', Extension)
project.stringcare.extensions.modules = project.container(Conf)
}
}
Expand Down
Binary file added src/main/groovy/jni/libsignKey.dll
Binary file not shown.
Binary file added src/main/groovy/jni/libsignKey.dylib
Binary file not shown.

0 comments on commit 861fc76

Please sign in to comment.