Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
efraespada committed Dec 15, 2017
1 parent 2cdd932 commit 17c2795
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 109 deletions.
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
repo under construction, sorry

# AndroidObfuscatorPlugin
# String Care Android Plugin

Gradle implementation
------------

root_project/build.gradle
```groovy
apply plugin: com.efraespada.stringobfuscatorplugin.StringObfuscatorPlugin
// root_project/build.gradle
apply plugin: com.stringcare.SCPlugin
buildscript {
ext {
stringcare_version = '0.1'
}
repositories {
mavenLocal()
jcenter()
}
dependencies {
// ...
classpath files('../AndroidLibrary/build/libs/stringobfuscatorplugin-1.0-SNAPSHOT.jar')
// ...
classpath "com.stringcare:plugin:$stringcare_version"
}
}
stringcare {
modules {
sample {
stringFiles = ['strings.xml',"other_file.xml"]
srcFolders = ['src/main', "other_folder"]
}
// root_folder/sample/src/main/res/.../strings.xml
// root_folder/sample/src/main/res/.../other_file.xml
// root_folder/sample/other_folder/res/.../strings.xml
// root_folder/sample/other_folder/res/.../other_file.xml
other_module {
srcFolders = ['src/moduleB']
}
// root_folder/other_module/src/moduleB/res/.../strings.xml
other_module_ {} //
// root_folder/other_module_/src/main/res/.../strings.xml
}
}
```
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'com.jfrog.bintray'

group 'com.efraespada'
group 'com.stringcare'
version '0.1'


Expand All @@ -41,7 +41,7 @@ install {
pom {
project {
packaging 'aar'
name 'SAndroid'
name 'StringCareAndroidPlugin'
url siteUrl
// Set your license
licenses {
Expand Down Expand Up @@ -75,7 +75,7 @@ bintray {
configurations = ['archives']
pkg {
repo = "maven"
name = "stringcare:plugin"
name = "StringCareAndroidPlugin"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.efraespada.stringobfuscatorplugin;
package com.stringcare;

import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
Expand Down
30 changes: 30 additions & 0 deletions src/main/groovy/com/stringcare/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.stringcare;

import java.util.List;

public class Config {

List<String> stringFiles;
List<String> srcFolders;

Config() {
// nothing to do here
}

List<String> getStringFiles() {
return stringFiles;
}

void setStringFiles(List<String> stringFiles) {
this.stringFiles = stringFiles;
}

List<String> getSrcFolders() {
return srcFolders;
}

void setSrcFolders(List<String> srcFolders) {
this.srcFolders = srcFolders;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.efraespada.stringobfuscatorplugin;
package com.stringcare;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static com.efraespada.stringobfuscatorplugin.PrintUtils.print;
import static com.stringcare.PrintUtils.print;

public class CredentialUtils {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package com.efraespada.stringobfuscatorplugin;
package com.stringcare;

import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;

import static com.efraespada.stringobfuscatorplugin.PrintUtils.print;
import static com.stringcare.PrintUtils.print;

public class FileUtils {

private static String variant;
private static String module;
private static String key;
private static Config config;

final static int maxToShow = 15;


private static final Map<String, String> files = new HashMap<>();

private FileUtils() {
// nothing to do here
}

public static void init(String key, String module, String variant) {
files.clear();
public static void init(String key, String module, String variant, Config config) {
FileUtils.key = key;
FileUtils.module = module;
FileUtils.variant = variant;
FileUtils.config = config;
}

public static String getTextFromFilePath(String path) {
Expand All @@ -37,8 +29,6 @@ public static String getTextFromFilePath(String path) {
String xml = "";
String inputFilePath = path;

if (true) print("reading " + inputFilePath);

String message = "";

File file = new File(inputFilePath);
Expand Down Expand Up @@ -83,41 +73,58 @@ public static String getString(BufferedReader br) {
// detect multiple sourceSet res.srcDirs
public static void backupStringResources() {
String currentPath = getCurrentPath();
currentPath += module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator;
File file = new File(currentPath);
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
for (String dir : directories) {
String pathToCopy = currentPath + dir + File.separator;
String pathToCheck = getCurrentPath() + module + File.separator + "resbackup" + File.separator + dir + File.separator;

try {
File toCopy = new File(pathToCopy + "strings.xml");
File toCheck = new File(pathToCheck + "strings.xml");
if (toCheck.exists()) {
toCheck.delete();
}
if (toCopy.exists()) {
copyFile(toCopy, toCheck);
for (String folder : config.getSrcFolders()) {
currentPath += module + File.separator + folder + File.separator + "res" + File.separator;
File file = new File(currentPath);
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
if (directories != null) {
for (String dir : directories) {
String pathToCopy = currentPath + dir + File.separator;
String pathToCheck = getCurrentPath() + module + File.separator + "resbackup" + File.separator + dir + File.separator;

for (String sFile : config.getStringFiles()) {
try {
File toCopy = new File(pathToCopy + sFile);
File toCheck = new File(pathToCheck + sFile);
if (toCheck.exists()) {
toCheck.delete();
}
if (toCopy.exists()) {
print("- " + toCopy.getParentFile().getName() + File.separator + toCopy.getName(), true);
copyFile(toCopy, toCheck);
}
} catch (IOException e) {
e.printStackTrace();
// TODO HANDLE ERROR
}
}
}
} catch (IOException e) {
e.printStackTrace();
// TODO HANDLE ERROR
} else {
PrintUtils.print("source folder not found: " + folder, true);
}
}
}

public static void encryptStringResources() {
String currentPath = getCurrentPath();
currentPath += module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator;
File file = new File(currentPath);
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
for (String dir : directories) {
String pathToEncrypt = currentPath + dir + File.separator;

File toEncrypt = new File(pathToEncrypt + "strings.xml");
if (toEncrypt.exists()) {
String encrypted = find(getTextFromFilePath(toEncrypt.getAbsolutePath()));
writeFile(toEncrypt, encrypted);
for (String folder : config.getSrcFolders()) {
currentPath += module + File.separator + folder + File.separator + "res" + File.separator;
File file = new File(currentPath);
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
if (directories != null) {
for (String dir : directories) {
String pathToEncrypt = currentPath + dir + File.separator;
for (String sFile : config.getStringFiles()) {
File toEncrypt = new File(pathToEncrypt + sFile);
if (toEncrypt.exists()) {
PrintUtils.print("- " + toEncrypt.getParentFile().getName() + File.separator + toEncrypt.getName(), true);
String encrypted = find(getTextFromFilePath(toEncrypt.getAbsolutePath()));
writeFile(toEncrypt, encrypted);
}
}
}
} else {
PrintUtils.print("source folder not found: " + folder, true);
}
}
}
Expand All @@ -126,23 +133,35 @@ public static void restoreStringResources() {
String currentPath = getCurrentPath() + module + File.separator + "resbackup" + File.separator;
File file = new File(currentPath);
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
for (String dir : directories) {
String pathToEncrypt = currentPath + dir + File.separator;
String pathRes = getCurrentPath() + module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator + dir + File.separator;

File toRestore = new File(pathToEncrypt + "strings.xml");
File toCheck = new File(pathRes + "strings.xml");

try {
copyFile(toRestore, toCheck);
} catch (IOException e) {
e.printStackTrace();
if (directories != null) {
File toRestore;
for (String dir : directories) {
String pathToRestore = currentPath + dir + File.separator;
for (String folder : config.getSrcFolders()) {
String pathRes = getCurrentPath() + module + File.separator + folder + File.separator + "res" + File.separator + dir + File.separator;

for (String sFile : config.getStringFiles()) {
toRestore = new File(pathToRestore + sFile);
File toCheck = new File(pathRes + sFile);
if (toRestore.exists()) {
try {
PrintUtils.print("- " + toCheck.getParentFile().getName() + File.separator + toCheck.getName(), true);
copyFile(toRestore, toCheck);
} catch (IOException e) {
e.printStackTrace();
}

toRestore.delete();
toRestore.getParentFile().delete();
}
}
}
}

toRestore.delete();
}
if (file.isDirectory()) {
file.delete();
if (file.isDirectory()) {
file.delete();
}
} else {
PrintUtils.print("restore folder not found");
}
}

Expand Down Expand Up @@ -192,7 +211,7 @@ public static String find(String xmlO) {

toShow = toShow.length() > maxToShow ? toShow.substring(0, maxToShow) + ".." : toShow;
encrypted = encrypted.length() > maxToShow ? encrypted.substring(0, maxToShow) + ".." : encrypted;
print("[" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""));
print("\t[" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""), true);
} catch (Exception e) {
print("error on " + result);
e.printStackTrace();
Expand All @@ -204,8 +223,6 @@ public static String find(String xmlO) {
if (xml1.indexOf(toFind1) <= 0) break;
}

print(content);

return content;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.efraespada.stringobfuscatorplugin.interfaces;
package com.stringcare;

public interface GradleHandlerCallback {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.efraespada.stringobfuscatorplugin;
package com.stringcare;

public class PrintUtils {

private final static String TAG = "stringobfuscatorplugin";
private static String variant;
private static String module;

Expand All @@ -20,8 +19,15 @@ public static void init(String module, String variant) {
* @param message
*/
public static void print(String message) {
print(message, false);
}
public static void print(String message, boolean tab) {
if (variant != null && module != null) {
System.out.println(":" + module + ":" + TAG + " - " + message);
if (!tab) {
System.out.println(":" + module + ":" + message);
} else {
System.out.println("\t" + message);
}
} else {
System.out.println(message);
}
Expand Down
Loading

0 comments on commit 17c2795

Please sign in to comment.