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,18 +53,34 @@ 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")) {
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"); 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,11 +89,33 @@ 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) {
@ -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,6 +167,9 @@ 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()) {
libs.mkdirs();
}
if (libs.exists()) { 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";
tools.start();*/ if (status == 0) {
unpackLibs(new File("D:\\ieda\\android_sdk_tools\\sdk_plugin\\69you\\libs"), new SmaliApkToolsPath() { 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 @Override
public void smaliPath(String path) { public void smaliPath(String path) {
System.out.println("over = " + 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();*/
/* unpackLibs(new File("D:\\ieda\\android_sdk_tools\\libs\\tmp"), new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("over = "+path);
}
});*/
}
} }

View File

@ -27,7 +27,7 @@ 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() {
@ -226,7 +226,16 @@ 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());
} }
@ -245,6 +254,9 @@ 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);
@ -270,6 +282,7 @@ public class SmaliUtils {
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) {
@ -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() {
@ -365,4 +380,54 @@ public class SmaliUtils {
} }
} }
} }
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;
@ -36,6 +45,7 @@ public class Tools {
} }
return sb.toString(); return sb.toString();
} }
public static int getRandomInt(int min, int max) { public static int getRandomInt(int min, int max) {
int i = new Random().nextInt(max); int i = new Random().nextInt(max);
if (i < min) { if (i < min) {
@ -43,6 +53,7 @@ public class Tools {
} }
return i; return i;
} }
public static void deleteFiles(String path) { public static void deleteFiles(String path) {
File files = new File(path); File files = new File(path);
if (files.exists()) { if (files.exists()) {
@ -55,6 +66,7 @@ public class Tools {
files.delete(); files.delete();
} }
} }
public static boolean copyFileToName(String srcFileName, String destFileName, String fileName, boolean overlay) { public static boolean copyFileToName(String srcFileName, String destFileName, String fileName, boolean overlay) {
File srcFile = new File(srcFileName); File srcFile = new File(srcFileName);
// 判断源文件是否存在 // 判断源文件是否存在
@ -110,6 +122,7 @@ public class Tools {
return false; return false;
} }
} }
/** /**
* 复制单个文件 * 复制单个文件
* *
@ -126,6 +139,7 @@ public class Tools {
return copyFileToName(srcFileName, destFileName, null, overlay); return copyFileToName(srcFileName, destFileName, null, overlay);
} }
} }
public static void copy_dir(String src, String desc) { public static void copy_dir(String src, String desc) {
try { try {
//System.out.println("拷贝文件:"+src+" -> "+desc); //System.out.println("拷贝文件:"+src+" -> "+desc);
@ -146,6 +160,7 @@ public class Tools {
} }
} }
private static boolean copyDir(String dir, String dest) { private static boolean copyDir(String dir, String dest) {
try { try {
//System.out.println("复制文件"+dir+""+dest); //System.out.println("复制文件"+dir+""+dest);
@ -192,6 +207,7 @@ public class Tools {
} }
return true; return true;
} }
public static void saveConfig(File file, String data) { public static void saveConfig(File file, String data) {
if (!file.exists()) { if (!file.exists()) {
try { try {
@ -212,6 +228,7 @@ public class Tools {
} }
} }
public static JSONObject loadConfig(File file) { public static JSONObject loadConfig(File file) {
JSONObject json = null; JSONObject json = null;
BufferedReader reader; BufferedReader reader;
@ -263,6 +280,7 @@ public class Tools {
} }
} }
private static void compress(File sourceFile, ZipOutputStream zos, String zipName, String name, boolean KeepDirStructure, boolean zipRootName) private static void compress(File sourceFile, ZipOutputStream zos, String zipName, String name, boolean KeepDirStructure, boolean zipRootName)
throws Exception { throws Exception {
byte[] buf = new byte[2 * 1024]; byte[] buf = new byte[2 * 1024];
@ -323,15 +341,18 @@ public class Tools {
} }
} }
} }
public static long calFileCRC32(File file) throws IOException { public static long calFileCRC32(File file) throws IOException {
FileInputStream fi = new FileInputStream(file); FileInputStream fi = new FileInputStream(file);
CheckedInputStream checksum = new CheckedInputStream(fi, new CRC32()); CheckedInputStream checksum = new CheckedInputStream(fi, new CRC32());
while (checksum.read() != -1) { } while (checksum.read() != -1) {
}
long temp = checksum.getChecksum().getValue(); long temp = checksum.getChecksum().getValue();
fi.close(); fi.close();
checksum.close(); checksum.close();
return temp; return temp;
} }
public static void toAJar(String dx, String inName, String outName) { public static void toAJar(String dx, String inName, String outName) {
try { try {
@ -356,6 +377,7 @@ public class Tools {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void outError(InputStream inputStream) { public static void outError(InputStream inputStream) {
try { try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
@ -368,6 +390,7 @@ public class Tools {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static boolean isWindowsRuntime() { public static boolean isWindowsRuntime() {
System.out.println(System.getProperties().getProperty("os.name")); System.out.println(System.getProperties().getProperty("os.name"));
return System.getProperties().getProperty("os.name").toLowerCase().contains("windows"); return System.getProperties().getProperty("os.name").toLowerCase().contains("windows");
@ -390,36 +413,116 @@ public class Tools {
return str.toString(); return str.toString();
} }
public static void main(String[] args) throws Exception {
String url="http://192.168.137.1:8000/nas/music/favorite/add.do";
String body="{\"md5s\":[\"4fec7b325eb3795ef8241dabcbc14a5f\",\"febbf27e0d558a2ab69ee814a6bdebfb\",\"86a2fa76cc0e6919f9869324c3b61ba3\"],\"fid\":-1,\"token\":\"PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk\"}";
JSONObject json=new JSONObject();
json.put("fileName","C:\\\\Users\\\\admin\\\\Music\\\\英雄联盟 - 涅槃 (Phoenix).flac");
String tmp;
StringBuilder str=new StringBuilder();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("POST");
connection.addRequestProperty("content-type","application/json");
connection.addRequestProperty("charset","UTF-8");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(5 * 1000);
connection.setReadTimeout(10 * 1000);
OutputStream outputStream = connection.getOutputStream();
outputStream.write(json.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(connection.getResponseCode());
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((tmp = reader.readLine()) != null) {
str.append(tmp);
}
System.out.println("[域名]" + url + " = [body]" + body.toString() + " -> [接收] " + str);
}
public static void deleteFile(String s) { public static void deleteFile(String s) {
System.out.println("删除文件:" + s); System.out.println("删除文件:" + s);
new File(s).delete(); 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"));*/