This commit is contained in:
yutou 2021-07-16 11:13:22 +08:00
parent e93b6f1b1e
commit 7cadd94a07
9 changed files with 779 additions and 440 deletions

View File

@ -43,7 +43,10 @@
}, },
"sdkPath":"D:\\Android_src\\kuku-android-sdk", "sdkPath":"D:\\Android_src\\kuku-android-sdk",
"csjPackageName":"com.iaalz.tzjyg", "csjPackageName":"com.iaalz.tzjyg",
"packageApkTool":"libs/apktool_2.4.1.jar", "packageApkTool":"libs/apktool_2.5.0.jar",
"unPackageApkTool":"libs/apktool_2.4.1.jar", "unPackageApkTool":"libs/apktool_2.5.0.jar",
"encryption":true "encryption":true,
"aapt":"aapt",
"android":" D:\\Android\\Sdk\\platforms\\android-30\\android.jar",
"baksmali":"libs/baksmali.jar"
} }

BIN
libs/apktool_2.5.0.jar Normal file

Binary file not shown.

BIN
libs/baksmali.jar Normal file

Binary file not shown.

BIN
libs/pinyin4j-2.5.0.jar Normal file

Binary file not shown.

View File

@ -21,6 +21,7 @@ import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.utils.ApkSignTools; import com.qy.utils.ApkSignTools;
import com.qy.utils.SmaliUtils; import com.qy.utils.SmaliUtils;
import com.qy.utils.StringUtils; import com.qy.utils.StringUtils;
import com.qy.utils.Tools;
import org.json.JSONObject; import org.json.JSONObject;
public class SmaliUi extends JFrame { public class SmaliUi extends JFrame {
@ -380,6 +381,7 @@ public class SmaliUi extends JFrame {
Desktop.getDesktop().open(new File(signTools.getApkFile().getAbsolutePath()+"_sign.apk").getParentFile()); Desktop.getDesktop().open(new File(signTools.getApkFile().getAbsolutePath()+"_sign.apk").getParentFile());
lblInfo.setText("签名完成"); lblInfo.setText("签名完成");
System.out.println("签名完成"); System.out.println("签名完成");
Tools.exec("adb install "+signTools.getApkFile().getAbsolutePath()+"_sign.apk");
} catch (IOException ioException) { } catch (IOException ioException) {
ioException.printStackTrace(); ioException.printStackTrace();
} }

View File

@ -1,11 +1,16 @@
package com.qy.utils; package com.qy.utils;
import com.qy.Interfaces.DialogInterface;
import com.qy.Interfaces.SmaliApkToolsPath; import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.ui.ApkSignUi; import com.qy.ui.ApkSignUi;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector; import java.util.Vector;
public class HeiHeiTools { public class HeiHeiTools {
@ -13,7 +18,7 @@ public class HeiHeiTools {
private File pluginPath; private File pluginPath;
public HeiHeiTools() { public HeiHeiTools() {
time = System.currentTimeMillis();
} }
public void setSdkPlugin(File pluginPath) { public void setSdkPlugin(File pluginPath) {
@ -22,6 +27,17 @@ public class HeiHeiTools {
public void setApk(File apk) { public void setApk(File apk) {
this.apk = apk; this.apk = apk;
if(parameterMap!=null&&parameterMap.containsValue("#apk")){
Tools.getPackageName(apk, new DialogInterface() {
@Override
public void onOut(Object data) {
super.onOut(data);
System.out.println("包名:"+data);
parameterMap.put("#{packageName}",data.toString());
parameterMap.put("${applicationId}",data.toString());
}
});
}
} }
public void start() { public void start() {
@ -29,6 +45,7 @@ public class HeiHeiTools {
utils.unPack(apk.getAbsolutePath(), new SmaliApkToolsPath() { utils.unPack(apk.getAbsolutePath(), new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
System.out.println("解包:" + path);
copyLibs(new File(path)); copyLibs(new File(path));
} }
}); });
@ -36,19 +53,35 @@ public class HeiHeiTools {
private SmaliApkToolsPath packaInter; private SmaliApkToolsPath packaInter;
private int getSmaliIndex(File smalipath) {
int i = 0;
for (File file : smalipath.listFiles()) {
if (file.getName().startsWith("smali")) {
i++;
}
}
return ++i;
}
private void copyLibs(File smaliPath) { private void copyLibs(File smaliPath) {
if (!new File(pluginPath.getAbsolutePath() + File.separator + "libs").exists()) { if (!new File(pluginPath.getAbsolutePath() + File.separator + "libs").exists()) {
copyAssets(smaliPath, new File(pluginPath.getAbsolutePath() + File.separator + "assets"));
} }
//copyAssets(smaliPath, new File(pluginPath.getAbsolutePath() + File.separator + "assets"));
unpackLibs(new File(pluginPath.getAbsolutePath() + File.separator + "libs"), new SmaliApkToolsPath() { unpackLibs(new File(pluginPath.getAbsolutePath() + File.separator + "libs"), new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
System.out.println("path = " + path);
File libs = new File(path); File libs = new File(path);
for (File file : libs.listFiles()) { for (File file : libs.listFiles()) {
if (file.isDirectory() && !"original".equals(file.getName())&& !"unknown".equals(file.getName())) { if (file.isDirectory() && file.getName().contains("smali")) {
Tools.copy_dir(file.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "smali"); if(smali_classes) {
Tools.copy_dir(file.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "smali_classes" + getSmaliIndex(smaliPath));
}else {
Tools.copy_dir(file.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "smali");
}
} }
if(file.isDirectory()&& "assets".equals(file.getName())){ if (file.isDirectory() && "assets".equals(file.getName())) {
Tools.copy_dir(file.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "assets"); Tools.copy_dir(file.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "assets");
} }
@ -56,21 +89,43 @@ public class HeiHeiTools {
packaInter = new SmaliApkToolsPath() { packaInter = new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
XMLTools.setParameter(parameterMap);
XMLTools.mergeManifestXML(new File(smaliPath.getAbsolutePath() + File.separator + "AndroidManifest.xml"), XMLTools.mergeManifestXML(new File(smaliPath.getAbsolutePath() + File.separator + "AndroidManifest.xml"),
new File(pluginPath.getAbsolutePath() + File.separator + "AndroidManifest.xml"), new File(pluginPath.getAbsolutePath() + File.separator + "AndroidManifest.xml"),
new File(smaliPath.getAbsolutePath() + File.separator + "AndroidManifest.xml")); new File(smaliPath.getAbsolutePath() + File.separator + "AndroidManifest.xml"));
File icon = new File(pluginPath.getAbsolutePath() + File.separator + iconName);
File splash_h=new File(pluginPath.getAbsolutePath() + File.separator +"ll_init_logo_h.png");
File splash_p=new File(pluginPath.getAbsolutePath() + File.separator +"ll_init_logo_p.png");
if (icon.exists()||splash_h.exists()||splash_p.exists()) {
File appSrc = new File(smaliPath.getAbsolutePath() + File.separator + "res");
for (File file : appSrc.listFiles()) {
if (file.getName().contains("drawable") || file.getName().contains("mipmap")) {
if (icon.exists()&&new File(file.getAbsolutePath() + File.separator + iconName).exists()) {
Tools.copyFile(icon.getAbsolutePath(), file.getAbsolutePath(), true);
}
if(splash_h.exists()&&new File(file.getAbsolutePath() + File.separator + "ll_init_logo_h.png").exists()){
Tools.copyFile(splash_h.getAbsolutePath(), file.getAbsolutePath(), true);
}
if(splash_p.exists()&&new File(file.getAbsolutePath() + File.separator + "ll_init_logo_p.png").exists()){
Tools.copyFile(splash_p.getAbsolutePath(), file.getAbsolutePath(), true);
}
}
}
}
SmaliUtils utils = new SmaliUtils(); SmaliUtils utils = new SmaliUtils();
utils.bale(smaliPath.getAbsolutePath(), smaliPath.getAbsolutePath()+File.separator+"game.apk", new SmaliApkToolsPath() { if(isOutR)
utils.outR(smaliPath.getAbsolutePath());
utils.bale(smaliPath.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + appPackageName, new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
LinkedHashMap<String,String> keyMap= ApkSignUi.loadKeys(); LinkedHashMap<String, String> keyMap = ApkSignUi.loadKeys();
Vector<String> adbList = new Vector<String>(keyMap.keySet()); Vector<String> adbList = new Vector<String>(keyMap.keySet());
String key=adbList.get(1); String key = adbList.get(1);
String tmp=keyMap.get(key); String tmp = keyMap.get(key);
System.out.println("选择签名:"+key); System.out.println("选择签名:" + key);
JSONObject json=new JSONObject(tmp); JSONObject json = new JSONObject(tmp);
ApkSignTools tools=new ApkSignTools(); ApkSignTools tools = new ApkSignTools();
tools.setSignFile(new File(json.getString("file"))); tools.setSignFile(new File(json.getString("file")));
tools.setApkFile(new File(path)); tools.setApkFile(new File(path));
tools.setKeyStorePassword(json.getString("alias_password")); tools.setKeyStorePassword(json.getString("alias_password"));
@ -79,6 +134,23 @@ public class HeiHeiTools {
System.out.println("开始签名"); System.out.println("开始签名");
tools.sign(); tools.sign();
System.out.println("打包完成:" + path); System.out.println("打包完成:" + path);
System.out.println("耗时:" + (System.currentTimeMillis() - time) / 1000 + "s");
try {
String exec = "adb install " + path.replace(appPackageName, appPackageName + "_sign.apk");
System.out.println("exec = " + exec);
Process process = Runtime.getRuntime().exec(exec);
InputStream inputStream = process.getInputStream();
StringBuilder builder = new StringBuilder();
int len;
byte[] bytes = new byte[1024];
while ((len = inputStream.read(bytes)) != -1) {
builder.append(new String(bytes, 0, len));
}
inputStream.close();
System.out.println(builder.toString());
} catch (IOException e) {
e.printStackTrace();
}
} }
}); });
} }
@ -95,7 +167,10 @@ public class HeiHeiTools {
private void copyJniLibs(File smaliPath, File jniLibs) { private void copyJniLibs(File smaliPath, File jniLibs) {
File libs = new File(smaliPath.getAbsolutePath() + File.separator + "lib"); File libs = new File(smaliPath.getAbsolutePath() + File.separator + "lib");
if(libs.exists()) { if (!libs.exists()) {
libs.mkdirs();
}
if (libs.exists()) {
for (File file : libs.listFiles()) { for (File file : libs.listFiles()) {
Tools.copy_dir(jniLibs.getAbsolutePath() + File.separator + file.getName(), file.getAbsolutePath()); Tools.copy_dir(jniLibs.getAbsolutePath() + File.separator + file.getName(), file.getAbsolutePath());
} }
@ -104,7 +179,8 @@ public class HeiHeiTools {
} }
private void copyRes(File smaliPath, File res) { private void copyRes(File smaliPath, File res) {
Tools.copy_dir(res.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "res"); //Tools.copy_dir(res.getAbsolutePath(), smaliPath.getAbsolutePath() + File.separator + "res");
XMLTools.copyResDir(res, new File(smaliPath.getAbsolutePath() + File.separator + "res"));
copyCode(smaliPath, new File(pluginPath.getAbsolutePath() + File.separator + "code")); copyCode(smaliPath, new File(pluginPath.getAbsolutePath() + File.separator + "code"));
} }
@ -138,8 +214,8 @@ public class HeiHeiTools {
private static void unpackLibs(File libs, SmaliApkToolsPath smaliApkToolsPath) { private static void unpackLibs(File libs, SmaliApkToolsPath smaliApkToolsPath) {
String dx = Tools.loadConfig(new File("config.cfg")).getString("dx"); String dx = Tools.loadConfig(new File("config.cfg")).getString("dx");
if (new File("tmp" + File.separator + "dex").exists()) { if (new File("tmp" + File.separator + "dxs").exists()) {
Tools.deleteFiles(new File("tmp" + File.separator + "dex").getAbsolutePath()); Tools.deleteFiles(new File("tmp" + File.separator + "dxs").getAbsolutePath());
} }
if (new File("tmp" + File.separator + "dx_smali").exists()) { if (new File("tmp" + File.separator + "dx_smali").exists()) {
Tools.deleteFiles(new File("tmp" + File.separator + "dx_smali").getAbsolutePath()); Tools.deleteFiles(new File("tmp" + File.separator + "dx_smali").getAbsolutePath());
@ -166,17 +242,59 @@ public class HeiHeiTools {
} }
} }
long time;
private static String iconName = "app_icon.png";
private static String appPackageName = "game.apk";
private static boolean isOutR=true;
private static boolean smali_classes=true;
private static Map<String, String> parameterMap;
public static void main(String[] args) { public static void main(String[] args) {
/* HeiHeiTools tools = new HeiHeiTools(); int status = 1;
tools.setApk(new File("D:\\ieda\\android_sdk_tools\\天命传说嘿嘿游戏专服_嘿嘿游戏_8.1.4_202106070951.apk")); String packageName = "com.game.test";
tools.setSdkPlugin(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\zssdk")); packageName = "com.rydts.heihei.m01";
if (status == 0) {
parameterMap = new HashMap<>();
parameterMap.put("${applicationId}", packageName);
parameterMap.put("#{packageName}",packageName);
HeiHeiTools tools = new HeiHeiTools();
tools.setApk(new File("D:\\ieda\\android_sdk_tools\\幻想圣域-母包.apk"));
tools.setSdkPlugin(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\mumayi"));
tools.start();
Tools.getPackageName(tools.apk, new DialogInterface() {
@Override
public void onOut(Object data) {
super.onOut(data);
System.out.println("APK包名 = "+data);
}
});
} else if (status == 1) {
parameterMap=new HashMap<>();
parameterMap.put("${applicationId}",packageName);
parameterMap.put("#{packageName}",packageName);
HeiHeiTools tools = new HeiHeiTools();
File file = new File("D:\\ieda\\android_sdk_tools\\热血神剑-创优.apk");
appPackageName = file.getName();
tools.setApk(file);
tools.setSdkPlugin(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\chuangyou"));
tools.start();
} else if (status == 2) {
unpackLibs(new File("D:\\ieda\\android_sdk_tools\\libs\\tmp"), new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("over = " + path);
}
});
}
/* tools.setApk(new File("D:\\ieda\\android_sdk_tools\\九州八荒录-朋克.apk"));
tools.setSdkPlugin(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\pengke"));
tools.start();*/ tools.start();*/
unpackLibs(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\69you\\libs"), new SmaliApkToolsPath() { /* unpackLibs(new File("D:\\ieda\\android_sdk_tools\\libs\\tmp"), new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
System.out.println("over = "+path); System.out.println("over = "+path);
} }
}); });*/
} }
} }

View File

@ -27,29 +27,29 @@ public class SmaliUtils {
public static void main(String[] args) { public static void main(String[] args) {
new SmaliUtils(); new SmaliUtils().outR("D:\\ieda\\android_sdk_tools\\HUANXIANGSHENGYU-MUBAO");
} }
public SmaliUtils() { public SmaliUtils() {
clazzList = new HashMap<>(); clazzList = new HashMap<>();
try { try {
JSONObject json =Tools.loadConfig(new File("config.cfg")); JSONObject json = Tools.loadConfig(new File("config.cfg"));
if(package_apktool ==null){ if (package_apktool == null) {
String path="libs/apktool_2.4.1.jar"; String path = "libs/apktool_2.4.1.jar";
if(json!=null){ if (json != null) {
path=json.optString("packageApkTool","libs/apktool_2.4.1.jar"); path = json.optString("packageApkTool", "libs/apktool_2.4.1.jar");
} }
System.out.println(path); System.out.println(path);
package_apktool =new URLClassLoader(new URL[]{new URL("file:"+path)}); package_apktool = new URLClassLoader(new URL[]{new URL("file:" + path)});
} }
if(un_apktool ==null){ if (un_apktool == null) {
String path="libs/apktool_2.4.1.jar"; String path = "libs/apktool_2.4.1.jar";
if(json!=null){ if (json != null) {
path=json.optString("unPackageApkTool","libs/apktool_2.4.1.jar"); path = json.optString("unPackageApkTool", "libs/apktool_2.4.1.jar");
} }
un_apktool =new URLClassLoader(new URL[]{new URL("file:"+path)}); un_apktool = new URLClassLoader(new URL[]{new URL("file:" + path)});
} }
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.exit(0); System.exit(0);
} }
@ -226,14 +226,23 @@ public class SmaliUtils {
private boolean isEncryption = true; private boolean isEncryption = true;
public void unPack(String jarPath, SmaliApkToolsPath smaliApkToolsPath) { public void unPack(String jarPath, SmaliApkToolsPath smaliApkToolsPath) {
File path = new File(jarPath + ".out"); File apk = new File(jarPath);
File path;
boolean isReName = false;
if (Tools.isContainChinese(apk.getName())) {
File tmp = new File(Tools.getPingYin(apk.getName()));
new File(jarPath).renameTo(tmp);
jarPath = tmp.getAbsolutePath();
isReName = true;
}
path = new File(jarPath + ".out");
if (path.exists() && path.isDirectory()) { if (path.exists() && path.isDirectory()) {
Tools.deleteFiles(path.getAbsolutePath()); Tools.deleteFiles(path.getAbsolutePath());
} }
String[] args = new String[]{"d", "-f", jarPath}; String[] args = new String[]{"d", "-f", jarPath};
JSONObject json=Tools.loadConfig(new File("config.cfg")); JSONObject json = Tools.loadConfig(new File("config.cfg"));
if(json!=null){ if (json != null) {
isEncryption=json.optBoolean("encryption",false); isEncryption = json.optBoolean("encryption", false);
} }
if (isEncryption) { if (isEncryption) {
args = new String[]{"d", "-f", jarPath, "--only-main-classes"}; args = new String[]{"d", "-f", jarPath, "--only-main-classes"};
@ -244,7 +253,10 @@ public class SmaliUtils {
} }
System.out.println("\n"); System.out.println("\n");
//Main.main(args); //Main.main(args);
un_apktool.loadClass("brut.apktool.Main").getMethod("main",String[].class).invoke(null,new Object[]{args}); un_apktool.loadClass("brut.apktool.Main").getMethod("main", String[].class).invoke(null, new Object[]{args});
if (isReName)
new File(jarPath).renameTo(apk);
// System.out.println(jarPath+" 重命名 "+path.getAbsolutePath());
File jarFile = new File(jarPath); File jarFile = new File(jarPath);
String name; String name;
if (jarFile.getName().contains(".jar")) { if (jarFile.getName().contains(".jar")) {
@ -252,7 +264,7 @@ public class SmaliUtils {
} else if (jarFile.getName().contains(".apk")) { } else if (jarFile.getName().contains(".apk")) {
name = jarFile.getName().replace(".apk", ""); name = jarFile.getName().replace(".apk", "");
} else { } else {
name = jarFile.getName(); name = path.getName();
} }
//jarFile.delete(); //jarFile.delete();
smaliApkToolsPath.smaliPath(new File("").getAbsolutePath() + File.separator + name); smaliApkToolsPath.smaliPath(new File("").getAbsolutePath() + File.separator + name);
@ -263,28 +275,29 @@ public class SmaliUtils {
} }
public void bale(String path, String smaliPath) { public void bale(String path, String smaliPath) {
run=false; run = false;
packageError=false; packageError = false;
bale(path, smaliPath, null); bale(path, smaliPath, null);
} }
public boolean run = false; public boolean run = false;
public static StringBuffer error=new StringBuffer(); public static StringBuffer error = new StringBuffer();
public void bale(String smaliPath, String path, SmaliApkToolsPath inter) { public void bale(String smaliPath, String path, SmaliApkToolsPath inter) {
String[] args = new String[]{"-r","b", "-f", smaliPath, "-o", path}; String[] args = new String[]{"-r", "b", "-f", smaliPath, "-o", path};
for (String string : args) { for (String string : args) {
System.err.print(string + " "); System.err.print(string + " ");
} }
try { try {
run = true; run = true;
error=new StringBuffer(); error = new StringBuffer();
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream); PrintStream printStream = new PrintStream(outputStream);
PrintStream old=System.err; PrintStream old = System.err;
System.setErr(printStream); System.setErr(printStream);
while (run) { while (run) {
byte[] bs = outputStream.toByteArray(); byte[] bs = outputStream.toByteArray();
@ -304,7 +317,7 @@ public class SmaliUtils {
System.setSecurityManager(new NoExitSecurityManager()); System.setSecurityManager(new NoExitSecurityManager());
//Main.main(args); //Main.main(args);
package_apktool.loadClass("brut.apktool.Main").getMethod("main",String[].class).invoke(null,new Object[]{args}); package_apktool.loadClass("brut.apktool.Main").getMethod("main", String[].class).invoke(null, new Object[]{args});
if (inter != null) { if (inter != null) {
inter.smaliPath(path); inter.smaliPath(path);
} }
@ -333,7 +346,9 @@ public class SmaliUtils {
public void setFilter(List<String> list) { public void setFilter(List<String> list) {
this.list = list; this.list = list;
} }
public static boolean packageError=false;
public static boolean packageError = false;
public static class NoExitSecurityManager extends SecurityManager { public static class NoExitSecurityManager extends SecurityManager {
public NoExitSecurityManager() { public NoExitSecurityManager() {
@ -359,10 +374,60 @@ public class SmaliUtils {
private static class ExitException extends SecurityException { private static class ExitException extends SecurityException {
public ExitException(int status) { public ExitException(int status) {
System.out.println("print exit :" + status); System.out.println("print exit :" + status);
if(error.length()>0){ if (error.length() > 0) {
packageError=true; packageError = true;
new TextToDialog("打包异常",error.toString()); new TextToDialog("打包异常", error.toString());
} }
} }
} }
public void outR(String smaliPath){
try {
File r=new File(smaliPath+File.separator+"R");
r.mkdirs();
File out=new File(smaliPath+File.separator+"out");
out.mkdirs();
JSONObject config= Tools.loadConfig(new File("config.cfg"));
String aapt=config.getString("aapt");
String android=config.getString("android");
String dx=config.getString("dx");
String baksmali=config.getString("baksmali");
Tools.exec(aapt+" p -m -J "+r.getAbsolutePath()+" -S "+smaliPath+File.separator+"res -M "+smaliPath+File.separator+"AndroidManifest.xml -I "+android);
File rjava=getR(r);
Tools.exec("javac "+rjava.getAbsolutePath());
rjava.delete();
Tools.toZip(r.listFiles()[0].getAbsolutePath(),new File(smaliPath+File.separator+"R"+File.separator+"classes.zip"),true,true);
Tools.exec("java -jar "+new File(dx).getAbsolutePath()+" --dex --output="+smaliPath+File.separator+"R"+File.separator+"classes.dex "+smaliPath+File.separator+"R"+File.separator+"classes.zip");
Tools.exec("java -jar "+new File(baksmali).getAbsolutePath()+" -o "+out.getAbsolutePath()+" "+smaliPath+File.separator+"R"+File.separator+"classes.dex");
File smalis=new File(smaliPath+File.separator+"smali");
/*for (File file : smalis.listFiles()) {
if(file.getName().startsWith("smali")){
File tr=getR(out);
if(tr==null)
tr=new File(smaliPath);
System.out.println("搜索:"+new File(file.getAbsolutePath()+File.separator+tr.getAbsolutePath().replace(smaliPath+File.separator+"out","")));
if(new File(file.getAbsolutePath()+File.separator+tr.getAbsolutePath().replace(smaliPath+File.separator+"out","")).exists()){
System.out.println("找到R文件:"+new File(file.getAbsolutePath()+File.separator+getR(out).getAbsolutePath().replace(smaliPath+File.separator+"out","")).getAbsolutePath());
Tools.copy_dir(out.getAbsolutePath(),file.getAbsolutePath());
}
}
}*/
Tools.copy_dir(out.getAbsolutePath(),smalis.getAbsolutePath());
}catch (Exception e){
e.printStackTrace();
}
}
private File getR(File dir){
if(dir.isFile()){
return dir;
}else{
for (File file : dir.listFiles()) {
return getR(file);
}
}
return null;
}
} }

View File

@ -5,13 +5,22 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.rmi.server.ExportException; import java.rmi.server.ExportException;
import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream; import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import com.qy.Interfaces.DialogInterface;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -19,407 +28,501 @@ import static java.util.zip.ZipEntry.STORED;
public class Tools { public class Tools {
public static boolean stringIsNull(String string) { public static boolean stringIsNull(String string) {
if (string == null || string.length() == 0) { if (string == null || string.length() == 0) {
return true; return true;
} }
return false; return false;
} }
public static String getRandomString(int length) { public static String getRandomString(int length) {
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random = new Random(); Random random = new Random();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
int number = random.nextInt(str.length()); int number = random.nextInt(str.length());
sb.append(str.charAt(number)); sb.append(str.charAt(number));
} }
return sb.toString(); return sb.toString();
} }
public static int getRandomInt(int min,int max) {
int i=new Random().nextInt(max);
if(i<min) {
return getRandomInt(min, max);
}
return i;
}
public static void deleteFiles(String path) {
File files = new File(path);
if (files.exists()) {
if (files.isDirectory()) {
for (File file : files.listFiles()) {
deleteFiles(file.getAbsolutePath());
}
}
// System.out.println("删除文件 "+files.getAbsolutePath());
files.delete();
}
}
public static boolean copyFileToName(String srcFileName,String destFileName,String fileName,boolean overlay) {
File srcFile = new File(srcFileName);
// 判断源文件是否存在
if (!srcFile.exists()) {
System.err.println("源文件不存在:"+srcFile.getAbsolutePath()+" > "+destFileName);
return false;
} else if (!srcFile.isFile()) {
System.err.println("源文件是目录:"+srcFile.getAbsolutePath());
return false;
}
// 判断目标文件是否存在 public static int getRandomInt(int min, int max) {
File destFile = new File(destFileName); int i = new Random().nextInt(max);
// 如果目标文件所在目录不存在则创建目录 if (i < min) {
if (!destFile.exists()) { return getRandomInt(min, max);
// 目标文件所在目录不存在 }
if (!destFile.mkdirs()) { return i;
// 复制文件失败创建目标文件所在目录失败 }
System.err.println("创建文件夹失败:"+destFile.getAbsolutePath());
return false;
}
}else{ public static void deleteFiles(String path) {
if(srcFileName.equals("Activity.smali")){ File files = new File(path);
System.out.println("文件夹已存在:"+destFileName); if (files.exists()) {
} if (files.isDirectory()) {
} for (File file : files.listFiles()) {
deleteFiles(file.getAbsolutePath());
}
}
// System.out.println("删除文件 "+files.getAbsolutePath());
files.delete();
}
}
// 复制文件 public static boolean copyFileToName(String srcFileName, String destFileName, String fileName, boolean overlay) {
int byteread = 0; // 读取的字节数 File srcFile = new File(srcFileName);
InputStream in = null; // 判断源文件是否存在
OutputStream out = null; if (!srcFile.exists()) {
System.err.println("源文件不存在:" + srcFile.getAbsolutePath() + " > " + destFileName);
return false;
} else if (!srcFile.isFile()) {
System.err.println("源文件是目录:" + srcFile.getAbsolutePath());
return false;
}
try { // 判断目标文件是否存在
if(fileName==null) { File destFile = new File(destFileName);
fileName=srcFile.getName(); // 如果目标文件所在目录不存在则创建目录
} if (!destFile.exists()) {
in = new FileInputStream(srcFile); // 目标文件所在目录不存在
out = new FileOutputStream(destFile + File.separator +fileName ); if (!destFile.mkdirs()) {
byte[] buffer = new byte[1024]; // 复制文件失败创建目标文件所在目录失败
System.err.println("创建文件夹失败:" + destFile.getAbsolutePath());
return false;
}
while ((byteread = in.read(buffer)) != -1) { } else {
out.write(buffer, 0, byteread); if (srcFileName.equals("Activity.smali")) {
} System.out.println("文件夹已存在:" + destFileName);
out.close(); }
in.close(); }
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* 复制单个文件
*
* @param srcFileName 待复制的文件名
* @param destFileName 目标文件名
* @param overlay 如果目标文件存在是否覆盖
* @return 如果复制成功返回true否则返回false
*/
public static boolean copyFile(String srcFileName, String destFileName,
boolean overlay) {
if(new File(srcFileName).isDirectory()){
return copyDir(srcFileName,destFileName);
}else {
return copyFileToName(srcFileName, destFileName, null, overlay);
}
}
public static void copy_dir(String src,String desc){
try {
//System.out.println("拷贝文件:"+src+" -> "+desc);
File dirSrc=new File(src);
if(!dirSrc.exists()){
return;
}
for (File file : dirSrc.listFiles()) {
if(file.isDirectory()){
new File(desc+File.separator+file.getName()).mkdirs();
copy_dir(file.getAbsolutePath(),desc+File.separator+file.getName());
}else{
copyFile(file.getAbsolutePath(),desc,true);
}
}
}catch (Exception e){
e.printStackTrace();
}
} // 复制文件
private static boolean copyDir(String dir,String dest){ int byteread = 0; // 读取的字节数
try{ InputStream in = null;
//System.out.println("复制文件"+dir+""+dest); OutputStream out = null;
File src=new File(dir);
File destFile=new File(dest);
String path="";
int index;
String ta,tb;
if(dir.length()>dest.length()){
index=dir.length();
ta=dir;
tb=dest;
}else{
index=dest.length();
ta=dest;
tb=dir;
}
for (int i = 0; i < index; i++) {
if(tb.length()>(i+1)&&ta.substring(i,i+1).equals(tb.substring(i,i+1))){
path+=ta.substring(i,i+1);
}else {
break;
}
}
if(!destFile.exists()){
destFile.mkdirs();
}
for (File file : src.listFiles()) {
if(file.isDirectory()){
copyDir(file.getAbsolutePath(),dest);
}else{
String tmp=file.getAbsolutePath().replace(file.getName(),"").replace(new File("input"+File.separator+"Documents"+File.separator+"copy"+File.separator).getAbsolutePath(),"");
System.out.println(file.getAbsolutePath()+" "+tmp);
File out=new File(dest+tmp);
if(!out.exists()){
out.mkdirs();
}
copyFile(file.getAbsolutePath(),out.getAbsolutePath(),true);
}
}
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
public static void saveConfig(File file,String data){
if(!file.exists()){
try {
if(!file.createNewFile()){
return;
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
OutputStream outputStream=new FileOutputStream(file);
outputStream.write(new String(data.getBytes(),StandardCharsets.UTF_8).getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
} try {
public static JSONObject loadConfig(File file) { if (fileName == null) {
JSONObject json = null; fileName = srcFile.getName();
BufferedReader reader; }
if (!file.exists()) { in = new FileInputStream(srcFile);
try { out = new FileOutputStream(destFile + File.separator + fileName);
file.createNewFile(); byte[] buffer = new byte[1024];
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String tmp, str = "";
try {
reader = new BufferedReader( new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
while ((tmp = reader.readLine()) != null) {
str += tmp;
}
reader.close();
json = new JSONObject(str);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(str);
}
}
return json;
}
public static void toZip(String srcDir, File file, boolean KeepDirStructure,boolean zipRootName) throws RuntimeException { while ((byteread = in.read(buffer)) != -1) {
out.write(buffer, 0, byteread);
}
out.close();
in.close();
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
long start = System.currentTimeMillis(); /**
ZipOutputStream zos = null; * 复制单个文件
try { *
zos = new ZipOutputStream(new FileOutputStream(file)); * @param srcFileName 待复制的文件名
File sourceFile = new File(srcDir); * @param destFileName 目标文件名
compress(sourceFile, zos,file.getName(), sourceFile.getName(), KeepDirStructure,zipRootName); * @param overlay 如果目标文件存在是否覆盖
long end = System.currentTimeMillis(); * @return 如果复制成功返回true否则返回false
System.out.println("压缩完成,耗时:" + (end - start) + " ms"); */
} catch (Exception e) { public static boolean copyFile(String srcFileName, String destFileName,
throw new RuntimeException("zip error from ZipUtils", e); boolean overlay) {
} finally { if (new File(srcFileName).isDirectory()) {
if (zos != null) { return copyDir(srcFileName, destFileName);
try { } else {
zos.close(); return copyFileToName(srcFileName, destFileName, null, overlay);
} catch (IOException e) { }
e.printStackTrace(); }
}
}
}
} public static void copy_dir(String src, String desc) {
private static void compress(File sourceFile, ZipOutputStream zos,String zipName, String name, boolean KeepDirStructure,boolean zipRootName) try {
throws Exception { //System.out.println("拷贝文件:"+src+" -> "+desc);
byte[] buf = new byte[ 2 * 1024]; File dirSrc = new File(src);
if (!dirSrc.exists()) {
return;
}
for (File file : dirSrc.listFiles()) {
if (file.isDirectory()) {
new File(desc + File.separator + file.getName()).mkdirs();
copy_dir(file.getAbsolutePath(), desc + File.separator + file.getName());
} else {
copyFile(file.getAbsolutePath(), desc, true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (sourceFile.isFile()) { }
if(sourceFile.getName().equals(zipName)){
return; private static boolean copyDir(String dir, String dest) {
} try {
// 向zip输出流中添加一个zip实体构造器中name为zip实体的文件的名字 //System.out.println("复制文件"+dir+""+dest);
ZipEntry entry=new ZipEntry(name); File src = new File(dir);
File destFile = new File(dest);
String path = "";
int index;
String ta, tb;
if (dir.length() > dest.length()) {
index = dir.length();
ta = dir;
tb = dest;
} else {
index = dest.length();
ta = dest;
tb = dir;
}
for (int i = 0; i < index; i++) {
if (tb.length() > (i + 1) && ta.substring(i, i + 1).equals(tb.substring(i, i + 1))) {
path += ta.substring(i, i + 1);
} else {
break;
}
}
if (!destFile.exists()) {
destFile.mkdirs();
}
for (File file : src.listFiles()) {
if (file.isDirectory()) {
copyDir(file.getAbsolutePath(), dest);
} else {
String tmp = file.getAbsolutePath().replace(file.getName(), "").replace(new File("input" + File.separator + "Documents" + File.separator + "copy" + File.separator).getAbsolutePath(), "");
System.out.println(file.getAbsolutePath() + " " + tmp);
File out = new File(dest + tmp);
if (!out.exists()) {
out.mkdirs();
}
copyFile(file.getAbsolutePath(), out.getAbsolutePath(), true);
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public static void saveConfig(File file, String data) {
if (!file.exists()) {
try {
if (!file.createNewFile()) {
return;
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
OutputStream outputStream = new FileOutputStream(file);
outputStream.write(new String(data.getBytes(), StandardCharsets.UTF_8).getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static JSONObject loadConfig(File file) {
JSONObject json = null;
BufferedReader reader;
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String tmp, str = "";
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
while ((tmp = reader.readLine()) != null) {
str += tmp;
}
reader.close();
json = new JSONObject(str);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(str);
}
}
return json;
}
public static void toZip(String srcDir, File file, boolean KeepDirStructure, boolean zipRootName) throws RuntimeException {
long start = System.currentTimeMillis();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new FileOutputStream(file));
File sourceFile = new File(srcDir);
compress(sourceFile, zos, file.getName(), sourceFile.getName(), KeepDirStructure, zipRootName);
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils", e);
} finally {
if (zos != null) {
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static void compress(File sourceFile, ZipOutputStream zos, String zipName, String name, boolean KeepDirStructure, boolean zipRootName)
throws Exception {
byte[] buf = new byte[2 * 1024];
if (sourceFile.isFile()) {
if (sourceFile.getName().equals(zipName)) {
return;
}
// 向zip输出流中添加一个zip实体构造器中name为zip实体的文件的名字
ZipEntry entry = new ZipEntry(name);
/*entry.setMethod(STORED); /*entry.setMethod(STORED);
entry.setSize(sourceFile.length()); entry.setSize(sourceFile.length());
long crc=0; long crc=0;
crc=calFileCRC32(sourceFile); crc=calFileCRC32(sourceFile);
entry.setCrc(crc);*/ entry.setCrc(crc);*/
zos.putNextEntry(entry); zos.putNextEntry(entry);
// copy文件到zip输出流中 // copy文件到zip输出流中
int len; int len;
FileInputStream in = new FileInputStream(sourceFile); FileInputStream in = new FileInputStream(sourceFile);
while ((len = in.read(buf)) != -1) { while ((len = in.read(buf)) != -1) {
zos.write(buf, 0, len); zos.write(buf, 0, len);
} }
// Complete the entry // Complete the entry
zos.closeEntry(); zos.closeEntry();
in.close(); in.close();
} else { } else {
File[] listFiles = sourceFile.listFiles(); File[] listFiles = sourceFile.listFiles();
if (listFiles == null || listFiles.length == 0) { if (listFiles == null || listFiles.length == 0) {
// 需要保留原来的文件结构时,需要对空文件夹进行处理 // 需要保留原来的文件结构时,需要对空文件夹进行处理
if (KeepDirStructure) { if (KeepDirStructure) {
// 空文件夹的处理 // 空文件夹的处理
ZipEntry entry=new ZipEntry(name + File.separator); ZipEntry entry = new ZipEntry(name + File.separator);
zos.putNextEntry(entry); zos.putNextEntry(entry);
// 没有文件不需要文件的copy // 没有文件不需要文件的copy
zos.closeEntry(); zos.closeEntry();
} }
} else { } else {
for (File file : listFiles) { for (File file : listFiles) {
// 判断是否需要保留原来的文件结构 // 判断是否需要保留原来的文件结构
if (KeepDirStructure) { if (KeepDirStructure) {
// 注意file.getName()前面需要带上父文件夹的名字加一斜杠, // 注意file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,所有文件都跑到压缩包根目录下了 // 不然最后压缩包中就不能保留原来的文件结构,所有文件都跑到压缩包根目录下了
if(zipRootName) { if (zipRootName) {
compress(file, zos, zipName,name + File.separator + file.getName(), KeepDirStructure,zipRootName); compress(file, zos, zipName, name + File.separator + file.getName(), KeepDirStructure, zipRootName);
}else{ } else {
if(name.startsWith("\\")){ if (name.startsWith("\\")) {
compress(file, zos, zipName,name + File.separator + file.getName(), KeepDirStructure,zipRootName); compress(file, zos, zipName, name + File.separator + file.getName(), KeepDirStructure, zipRootName);
}else { } else {
compress(file, zos,zipName, File.separator + file.getName(), KeepDirStructure, zipRootName); compress(file, zos, zipName, File.separator + file.getName(), KeepDirStructure, zipRootName);
} }
} }
} else { } else {
compress(file, zos, zipName,file.getName(), KeepDirStructure,zipRootName); compress(file, zos, zipName, file.getName(), KeepDirStructure, zipRootName);
} }
} }
} }
} }
} }
public static long calFileCRC32(File file) throws IOException {
FileInputStream fi = new FileInputStream(file);
CheckedInputStream checksum = new CheckedInputStream(fi, new CRC32());
while (checksum.read() != -1) { }
long temp = checksum.getChecksum().getValue();
fi.close();
checksum.close();
return temp;
}
public static void toAJar(String dx,String inName,String outName) {
try { public static long calFileCRC32(File file) throws IOException {
File file=new File(outName); FileInputStream fi = new FileInputStream(file);
if(file.exists()) { CheckedInputStream checksum = new CheckedInputStream(fi, new CRC32());
file.delete(); while (checksum.read() != -1) {
} }
String exec="java -jar "+dx+" --dex --output="+outName+" "+inName+""; long temp = checksum.getChecksum().getValue();
System.out.println("java to dex:"+exec); fi.close();
Process process=Runtime.getRuntime().exec(exec); checksum.close();
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getErrorStream())); return temp;
System.out.println("read"); }
String tmp=reader.readLine();
while (tmp!=null){
System.out.println(tmp);
tmp=reader.readLine();
}
process.waitFor();
System.out.println("打包完成");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void outError(InputStream inputStream){
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String tmp;
while ((tmp = reader.readLine()) != null) {
System.out.println(tmp);
}
reader.close();
}catch (Exception e){
e.printStackTrace();
}
}
public static boolean isWindowsRuntime(){
System.out.println(System.getProperties().getProperty("os.name"));
return System.getProperties().getProperty("os.name").toLowerCase().contains("windows");
}
public static String readFile(File manifest) { public static void toAJar(String dx, String inName, String outName) {
String tmp;
StringBuilder str = new StringBuilder();
try {
BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(manifest), StandardCharsets.UTF_8));
while ((tmp = reader.readLine()) != null) {
str.append(tmp);
}
reader.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(str);
}
return str.toString();
}
public static void main(String[] args) throws Exception { try {
String url="http://192.168.137.1:8000/nas/music/favorite/add.do"; File file = new File(outName);
String body="{\"md5s\":[\"4fec7b325eb3795ef8241dabcbc14a5f\",\"febbf27e0d558a2ab69ee814a6bdebfb\",\"86a2fa76cc0e6919f9869324c3b61ba3\"],\"fid\":-1,\"token\":\"PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk\"}"; if (file.exists()) {
JSONObject json=new JSONObject(); file.delete();
json.put("fileName","C:\\\\Users\\\\admin\\\\Music\\\\英雄联盟 - 涅槃 (Phoenix).flac"); }
String tmp; String exec = "java -jar " + dx + " --dex --output=" + outName + " " + inName + "";
StringBuilder str=new StringBuilder(); System.out.println("java to dex:" + exec);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); Process process = Runtime.getRuntime().exec(exec);
connection.setRequestMethod("POST"); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
connection.addRequestProperty("content-type","application/json"); System.out.println("read");
connection.addRequestProperty("charset","UTF-8"); String tmp = reader.readLine();
connection.setDoOutput(true); while (tmp != null) {
connection.setDoInput(true); System.out.println(tmp);
connection.setConnectTimeout(5 * 1000); tmp = reader.readLine();
connection.setReadTimeout(10 * 1000); }
OutputStream outputStream = connection.getOutputStream(); process.waitFor();
System.out.println("打包完成");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
outputStream.write(json.toString().getBytes()); public static void outError(InputStream inputStream) {
outputStream.flush(); try {
outputStream.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
System.out.println(connection.getResponseCode()); String tmp;
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); while ((tmp = reader.readLine()) != null) {
while ((tmp = reader.readLine()) != null) { System.out.println(tmp);
str.append(tmp); }
} reader.close();
System.out.println("[域名]" + url + " = [body]" + body.toString() + " -> [接收] " + str); } catch (Exception e) {
} e.printStackTrace();
}
}
public static void deleteFile(String s) { public static boolean isWindowsRuntime() {
System.out.println("删除文件:"+s); System.out.println(System.getProperties().getProperty("os.name"));
new File(s).delete(); return System.getProperties().getProperty("os.name").toLowerCase().contains("windows");
} }
public static String readFile(File manifest) {
String tmp;
StringBuilder str = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(manifest), StandardCharsets.UTF_8));
while ((tmp = reader.readLine()) != null) {
str.append(tmp);
}
reader.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(str);
}
return str.toString();
}
public static void deleteFile(String s) {
System.out.println("删除文件:" + s);
new File(s).delete();
}
public static boolean isContainChinese(String str) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
return true;
}
return false;
}
public static String getPingYin(String data) {
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
char[] datas = data.toCharArray();
StringBuilder builder = new StringBuilder();
for (char c : datas) {
try {
builder.append(PinyinHelper.toHanyuPinyinStringArray(c, format)[0].replace(":",""));
} catch (Exception badHanyuPinyinOutputFormatCombination) {
builder.append(c);
}
}
return builder.toString();
}
public static void exec(String exec, DialogInterface dialogInterface) {
try {
System.out.println("exec = " + exec);
Process process;
if (isRuntimeSystemOfWindow()) {
process = Runtime.getRuntime().exec(new String[]{
"cmd",
"/c",
exec
}
);
} else {
process = Runtime.getRuntime().exec(new String[]{
"sh",
"-c",
exec
}
);
}
if (dialogInterface != null) {
dialogInterface.onOut("input\n" + processOut(process.getInputStream()));
dialogInterface.onOut("output\n" + processOut(process.getErrorStream()));
} else {
processOut(process.getInputStream());
processOut(process.getErrorStream());
}
process.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void exec(String exec) {
exec(exec, null);
}
public static boolean isRuntimeSystemOfWindow() {
return System.getProperty("os.name").contains("Windows");
}
public static String processOut(InputStream inputStream) {
String tmp;
StringBuilder str = new StringBuilder("null");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
while ((tmp = reader.readLine()) != null) {
str.append(tmp).append("\n");
}
reader.close();
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return str.toString();
}
public static void getPackageName(File apk,DialogInterface dialogInterface) {
exec("aapt dump badging " + apk.getAbsolutePath(), new DialogInterface() {
@Override
public void onOut(Object data) {
super.onOut(data);
String[] infos=data.toString().split("\n");
for (String info : infos) {
if(info.contains("package")) {
dialogInterface.onOut(info.split("\'")[1]);
}
}
}
});
}
public static void main(String[] args) {
getPackageName(new File("D:\\ieda\\android_sdk_tools\\10051_kuku_202107132125.apk"), new DialogInterface() {
@Override
public void onOut(Object data) {
super.onOut(data);
System.out.println(data);
}
});
}
} }

View File

@ -6,18 +6,19 @@ import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import java.io.File; import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class XMLTools { public class XMLTools {
private static Map<String,String> parameterMap;
private XMLTools() { private XMLTools() {
} }
public static void setParameter(Map<String,String> map){
parameterMap=map;
}
public static void mergeManifestXML(File src,File src2,File outFile){ public static void mergeManifestXML(File src,File src2,File outFile){
try { try {
SAXReader reader = new SAXReader(); SAXReader reader = new SAXReader();
@ -44,7 +45,34 @@ public class XMLTools {
manifestDocument.remove(manifestElement); manifestDocument.remove(manifestElement);
manifestDocument.add((Element) manifestElement.clone()); manifestDocument.add((Element) manifestElement.clone());
writeFile4Pretty(outFile,manifestDocument); writeFile4Pretty(outFile,manifestDocument);
if(parameterMap!=null){
BufferedReader bufferedReader=new BufferedReader(new FileReader(outFile));
StringBuilder builder=new StringBuilder();
String tmp;
while ((tmp=bufferedReader.readLine())!=null){
for (String key : parameterMap.keySet()) {
if(tmp.contains(key)){
tmp=tmp.replace(key,parameterMap.get(key));
}
}
if(tmp.contains("package=")&&parameterMap.containsKey("#{packageName}")){
String[] sp=tmp.split("package=\"");
String[] sp2=sp[1].split("\"");
String t2="";
for (int i = 1; i < sp2.length; i++) {
t2+=sp2[i]+"\"";
}
System.out.println("t2 = " + t2);
tmp=sp[0]+"package=\""+parameterMap.get("#{packageName}")+"\""+t2.substring(0,t2.length()-1);
System.out.println("tmp = " + tmp);
}
builder.append(tmp).append("\n");
}
Tools.saveConfig(outFile,builder.toString());
}
System.out.println("AndroidManifest处理完成"); System.out.println("AndroidManifest处理完成");
parameterMap=null;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -65,6 +93,11 @@ public class XMLTools {
*/ */
public static void mergeResXML(File file1, File file2, File outFile) { public static void mergeResXML(File file1, File file2, File outFile) {
try { try {
if(!file1.getName().endsWith(".xml")||!file2.getName().endsWith(".xml")){
System.out.println("非xml 复制:"+file1.getAbsolutePath()+" -> "+outFile.getAbsolutePath());
Tools.copyFile(file1.getAbsolutePath(),outFile.getAbsolutePath().replace(file1.getName(),""),true);
return;
}
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
List<String> list1 = readXML(file1); List<String> list1 = readXML(file1);
List<String> list2 = readXML(file2); List<String> list2 = readXML(file2);
@ -195,10 +228,23 @@ public class XMLTools {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void copyResDir(File src,File target){
for (File file : src.listFiles()) {
if(file.isDirectory()){
copyResDir(file,new File(target.getAbsolutePath()+File.separator+file.getName()));
}else{
File targetFile=new File(target.getAbsolutePath()+File.separator+file.getName());
if(targetFile.exists()){
mergeResXML(file,targetFile,targetFile);
}else{
Tools.copyFile(file.getAbsolutePath(),target.getAbsolutePath(),true);
}
}
}
}
public static void main(String[] args) { public static void main(String[] args) {
boolean isPublic=true; boolean isPublic=true;
if(isPublic) { /* if(isPublic) {
mergePublicXML(new File("D:\\ieda\\android_sdk_tools\\EmptyDemo\\res\\values\\public.xml") mergePublicXML(new File("D:\\ieda\\android_sdk_tools\\EmptyDemo\\res\\values\\public.xml")
, new File("D:\\ieda\\android_sdk_tools\\app-game_op2-release\\res\\values\\public.xml") , new File("D:\\ieda\\android_sdk_tools\\app-game_op2-release\\res\\values\\public.xml")
, new File("D:\\ieda\\android_sdk_tools\\app-game_op2-release\\res\\values\\public.xml")); , new File("D:\\ieda\\android_sdk_tools\\app-game_op2-release\\res\\values\\public.xml"));
@ -207,7 +253,9 @@ public class XMLTools {
mergeResXML(new File("D:\\ieda\\android_sdk_tools\\qztx_agent_115847_baoliang_11027_1003.0.0_20210128_48301\\res\\values\\" + fileName), mergeResXML(new File("D:\\ieda\\android_sdk_tools\\qztx_agent_115847_baoliang_11027_1003.0.0_20210128_48301\\res\\values\\" + fileName),
new File("D:\\ieda\\android_sdk_tools\\EmptyDemo\\res\\values\\" + fileName), new File("D:\\ieda\\android_sdk_tools\\EmptyDemo\\res\\values\\" + fileName),
new File("D:\\ieda\\android_sdk_tools\\qztx_agent_115847_baoliang_11027_1003.0.0_20210128_48301\\res\\values\\" + fileName)); new File("D:\\ieda\\android_sdk_tools\\qztx_agent_115847_baoliang_11027_1003.0.0_20210128_48301\\res\\values\\" + fileName));
} }*/
copyResDir(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\nalan\\res"),
new File("D:\\ieda\\android_sdk_tools\\漫斗纪元-那蓝\\res"));
/*mergeManifestXML(new File("D:\\ieda\\android_sdk_tools\\三生诀\\AndroidManifest.xml"), /*mergeManifestXML(new File("D:\\ieda\\android_sdk_tools\\三生诀\\AndroidManifest.xml"),
new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\binghu\\AndroidManifest.xml"), new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\binghu\\AndroidManifest.xml"),
new File("D:\\ieda\\android_sdk_tools\\三生诀\\Manifest.xml"));*/ new File("D:\\ieda\\android_sdk_tools\\三生诀\\Manifest.xml"));*/