Commit 255bd155 authored by Administrator's avatar Administrator

支持通过apk作为模版产生破解项目

parent 9d461921
...@@ -21,3 +21,27 @@ virjar-share:ratel-demo virjar$ ...@@ -21,3 +21,27 @@ virjar-share:ratel-demo virjar$
执行完即可看到在本项目生成的子模块: 执行完即可看到在本项目生成的子模块:
![template-demo.png](template-demo.png) ![template-demo.png](template-demo.png)
你还可以通过一个apk构建破解模版,如:
```
virjar-share:ratel-demo virjar$ ./template.sh -a ~/Downloads/com.youdao.dict_7.8.7_7080700.apk
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
> Configure project :crack-demoapp
Observed package id 'ndk-bundle' in inconsistent location '/Users/virjar/Library/Android/sdk/disable-ndk-bundle-15' (Expected '/Users/virjar/Library/Android/sdk/ndk-bundle')
Observed package id 'ndk-bundle' in inconsistent location '/Users/virjar/Library/Android/sdk/ndk-bundle-broken' (Expected '/Users/virjar/Library/Android/sdk/ndk-bundle')
Already observed package id 'ndk-bundle' in '/Users/virjar/Library/Android/sdk/ndk-bundle'. Skipping duplicate at '/Users/virjar/Library/Android/sdk/ndk-bundle-broken'
Observed package id 'ndk-bundle' in inconsistent location '/Users/virjar/Library/Android/sdk/ndk-bundle-ollvm' (Expected '/Users/virjar/Library/Android/sdk/ndk-bundle')
Already observed package id 'ndk-bundle' in '/Users/virjar/Library/Android/sdk/ndk-bundle'. Skipping duplicate at '/Users/virjar/Library/Android/sdk/ndk-bundle-ollvm'
> Task :createhelper:compileJava
警告: [options] 未与 -source 1.7 一起设置引导类路径
1 个警告
BUILD SUCCESSFUL in 7s
2 actionable tasks: 2 executed
param: -a /Users/virjar/Downloads/com.youdao.dict_7.8.7_7080700.apk
virjar-share:ratel-demo virjar$
```
\ No newline at end of file
...@@ -17,6 +17,7 @@ dependencies { ...@@ -17,6 +17,7 @@ dependencies {
api 'commons-cli:commons-cli:1.4' api 'commons-cli:commons-cli:1.4'
api 'commons-io:commons-io:2.6' api 'commons-io:commons-io:2.6'
api 'org.apache.ant:ant:1.10.5' api 'org.apache.ant:ant:1.10.5'
api 'net.dongliu:apk-parser:2.6.10'
} }
sourceCompatibility = "7" sourceCompatibility = "7"
......
package com.virjar.ratel.createhelper; package com.virjar.ratel.createhelper;
import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
...@@ -19,6 +22,7 @@ import java.io.FileInputStream; ...@@ -19,6 +22,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Locale;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
...@@ -39,6 +43,7 @@ public class Main { ...@@ -39,6 +43,7 @@ public class Main {
options.addOption(new Option("p", "package", true, "in many case, we need crack a certain apk")); options.addOption(new Option("p", "package", true, "in many case, we need crack a certain apk"));
options.addOption(new Option("f", "force", false, "force overwrite")); options.addOption(new Option("f", "force", false, "force overwrite"));
options.addOption(new Option("t", "template-dir", true, "a project for template")); options.addOption(new Option("t", "template-dir", true, "a project for template"));
options.addOption(new Option("a", "apk", true, "path to apk"));
options.addOption(new Option("h", "help", false, "show help message")); options.addOption(new Option("h", "help", false, "show help message"));
...@@ -53,6 +58,16 @@ public class Main { ...@@ -53,6 +58,16 @@ public class Main {
return; return;
} }
Context context = new Context();
ApkMeta apkMeta = null;
if (cmd.hasOption('a')) {
try (ApkFile apkFile = new ApkFile(new File(cmd.getOptionValue('a')))) {
apkFile.setPreferredLocale(Locale.ENGLISH);
apkMeta = apkFile.getApkMeta();
}
}
// template-dir // template-dir
File templateDir = null; File templateDir = null;
if (cmd.hasOption('t')) { if (cmd.hasOption('t')) {
...@@ -74,15 +89,34 @@ public class Main { ...@@ -74,15 +89,34 @@ public class Main {
return; return;
} }
if (cmd.hasOption('m')) {
if (!cmd.hasOption('m')) { context.moduleName = cmd.getOptionValue('m');
} else if (apkMeta == null) {
System.out.println("need module name"); System.out.println("need module name");
HelpFormatter hf = new HelpFormatter(); HelpFormatter hf = new HelpFormatter();
hf.setWidth(110); hf.setWidth(110);
hf.printHelp("create-helper", options); hf.printHelp("create-helper", options);
return; return;
} else {
String label = apkMeta.getLabel();
boolean passed = true;
for (char character : label.toCharArray()) {
if (Character.isLetterOrDigit(character)) {
continue;
}
if (character == '-' || character == '_') {
continue;
}
passed = false;
break;
}
if (passed) {
context.moduleName = "crack-" + label;
} else {
context.moduleName = "crack-" + apkMeta.getPackageName().replaceAll("\\.", "-");
}
} }
final File modulePath = new File(templateDir.getParentFile(), cmd.getOptionValue('m')); final File modulePath = new File(templateDir.getParentFile(), context.moduleName);
boolean force = false; boolean force = false;
if (cmd.hasOption('f')) { if (cmd.hasOption('f')) {
force = true; force = true;
...@@ -118,19 +152,25 @@ public class Main { ...@@ -118,19 +152,25 @@ public class Main {
String applicationId; String applicationId;
if (cmd.hasOption('p')) { if (cmd.hasOption('p')) {
applicationId = "ratel.crack." + cmd.getOptionValue('p'); applicationId = "ratel.crack." + cmd.getOptionValue('p');
} else if (apkMeta != null) {
applicationId = "ratel." + apkMeta.getPackageName();
} else { } else {
applicationId = "ratel." + cmd.getOptionValue('m').replaceAll("-", "."); applicationId = "ratel." + context.moduleName.replaceAll("-", ".");
} }
String appName = cmd.getOptionValue('m');
Context context = new Context();
context.applicationId = applicationId; context.applicationId = applicationId;
context.appName = appName; if (apkMeta != null) {
context.appName = "crack-" + apkMeta.getLabel();
} else {
context.appName = context.moduleName;
}
context.outDir = modulePath; context.outDir = modulePath;
context.moduleName = cmd.getOptionValue('m');
if (cmd.hasOption('p')) { if (cmd.hasOption('p')) {
context.forApp = cmd.getOptionValue('p').trim(); context.forApp = cmd.getOptionValue('p').trim();
} else if (apkMeta != null) {
context.forApp = apkMeta.getPackageName();
} }
editBuildGradle(context); editBuildGradle(context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment