apktool改为动态加载形式

打包使用2.3.4版本,拆包使用2.4.1版本
This commit is contained in:
yutou 2020-10-20 17:16:29 +08:00
parent c8a82d2ba8
commit ca4518724a
10 changed files with 60 additions and 33 deletions

BIN
libs/apktool_2.3.4.jar Normal file

Binary file not shown.

View File

@ -3,8 +3,8 @@ package com.qy.ui;
import javax.swing.*;
import com.qy.utils.ApkSignTools;
import com.qy.utils.StringUtils;
import com.qy.utils.Tools;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import java.awt.event.ActionListener;

View File

@ -50,7 +50,7 @@ public class AppMain extends JFrame {
private JMenuItem mntmBase;
private static String cscPath = null;
private static String savePath=null;
private static String savePath = null;
public static void main(String[] args) {
/*args = new String[]{"-package=com.test.abc"
@ -69,7 +69,7 @@ public class AppMain extends JFrame {
String model = "csj";
String jarPath = null;
String jarType = null;
String config=null;
String config = null;
int index = -1;
@ -101,11 +101,11 @@ public class AppMain extends JFrame {
if (arg.startsWith("-index")) {
index = Integer.parseInt(arg.replace("-index=", "").trim());
}
if(arg.startsWith("-save")){
savePath= arg.replace("-save=", "");
if (arg.startsWith("-save")) {
savePath = arg.replace("-save=", "");
}
if(arg.startsWith("-config")){
config=arg.replace("-config=", "");
if (arg.startsWith("-config")) {
config = arg.replace("-config=", "");
}
if (arg.trim().equals("-h")) {
outHelp();
@ -114,7 +114,7 @@ public class AppMain extends JFrame {
}
if (model.equals("csj")) {
if (packageName != null && version != null && apkPath != null && csjPath != null) {
new CsjTools(apkPath, csjPath, packageName, version,config, new SmaliApkToolsPath() {
new CsjTools(apkPath, csjPath, packageName, version, config, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
if (cscPath != null) {
@ -140,7 +140,7 @@ public class AppMain extends JFrame {
new File(path).renameTo(new File(savePath));
}
});
}else if(model.equals("sdk")){
} else if (model.equals("sdk")) {
new AutoPackageSDK(path -> new File(path).renameTo(new File(savePath)), version, packageName);
}
@ -155,7 +155,7 @@ public class AppMain extends JFrame {
"\n-csc csc save Path csc保存路径" +
"\n-jar adsdk.jar path 需要被修改的sdk路径" +
"\n-type sdk type sdk类型" +
"\n-index ad_config.cfg index 在ad_config.cfg配置中的array下标"+
"\n-index ad_config.cfg index 在ad_config.cfg配置中的array下标" +
"\n-save save jar path 保存jar的路径"
);
}
@ -198,6 +198,7 @@ public class AppMain extends JFrame {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String tmp;
while ((tmp = reader.readLine()) != null) {
if (!StringUtils.isEmpty(tmp))
phonePackageList.add(tmp.substring(8));
}
Collections.sort(phonePackageList);
@ -223,7 +224,7 @@ public class AppMain extends JFrame {
// TODO: handle exception
e.printStackTrace();
}
setTitle("\u8F6C\u6362\u5668v2.2");
setTitle("\u8F6C\u6362\u5668v2.3");
// TODO Auto-generated constructor stub
setSize(900, 456);
getContentPane().setLayout(null);

View File

@ -4,8 +4,8 @@ import com.qy.Interfaces.DialogInterface;
import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.utils.ApkSignTools;
import com.qy.utils.AutoOutAPKTools;
import com.qy.utils.StringUtils;
import com.qy.utils.Tools;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import javax.swing.*;

View File

@ -20,7 +20,7 @@ import com.qy.Interfaces.DialogInterface;
import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.utils.ApkSignTools;
import com.qy.utils.SmaliUtils;
import org.apache.commons.lang3.StringUtils;
import com.qy.utils.StringUtils;
import org.json.JSONObject;
public class SmaliUi extends JFrame {
@ -95,7 +95,7 @@ public class SmaliUi extends JFrame {
// TODO: handle exception
e.printStackTrace();
}
setTitle("Smali\u53CD\u7F16\u8BD1\u5DE5\u5177v1.3");
setTitle("Smali\u53CD\u7F16\u8BD1\u5DE5\u5177v1.4");
// TODO Auto-generated constructor stub
setSize(900, 673);
getContentPane().setLayout(null);

View File

@ -38,6 +38,7 @@ public class ApkSignTools {
System.out.println(tmp);
}
reader.close();
process.destroy();
return true;
} catch (Exception e) {
// TODO Auto-generated catch block

View File

@ -34,6 +34,7 @@ public class AutoOutAPKTools {
outLog("复制游戏文件夹");
String newAppPath=appPath+"_"+gameId+"_"+Tools.getRandomString(6);
Tools.copy_dir(appPath,newAppPath);
String oldPath=appPath;
outLog("游戏游戏文件夹复制完成");
appPath=newAppPath;
outLog("修改Manifest");
@ -41,10 +42,10 @@ public class AutoOutAPKTools {
outLog("Manifest修改完成开始生成assets");
outAssets();
outLog("生成完毕");
new SmaliUtils().bale(appPath, appPath + File.separator + "game_.apk", new SmaliApkToolsPath() {
new SmaliUtils().bale(appPath, appPath + File.separator + new File(oldPath).getName()+gameId, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
inter.smaliPath(appPath + File.separator + "game_.apk");
inter.smaliPath(appPath + File.separator + new File(oldPath).getName()+gameId);
}
});
}

View File

@ -1,6 +1,8 @@
package com.qy.utils;
import java.io.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.ByteBuffer;
import java.security.Permission;
import java.util.ArrayList;
@ -8,15 +10,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import brut.androlib.Androlib;
import brut.androlib.res.xml.ResXmlPatcher;
import com.qy.Interfaces.SmaliApkToolsPath;
import brut.apktool.Main;
import com.qy.ui.TextToDialog;
import com.sun.javaws.exceptions.ExitException;
@ -27,6 +23,9 @@ public class SmaliUtils {
// private String mainPath = "D:\\反编译\\APK\\rx.jar.out\\smali";
private Map<String, String> clazzList;
private List<File> files = new ArrayList<>();
private static ClassLoader apktool_234;
private static ClassLoader apktool_241;
public static void main(String[] args) {
new SmaliUtils();
@ -34,6 +33,17 @@ public class SmaliUtils {
public SmaliUtils() {
clazzList = new HashMap<>();
try {
if(apktool_234==null){
apktool_234=new URLClassLoader(new URL[]{new URL("file:libs/apktool_2.3.4.jar")});
}
if(apktool_241==null){
apktool_241=new URLClassLoader(new URL[]{new URL("file:libs/apktool_2.4.1.jar")});
}
}catch (Exception e){
e.printStackTrace();
System.exit(0);
}
}
public void setPath(String uPath) {
@ -219,7 +229,9 @@ public class SmaliUtils {
for (String arg : args) {
System.out.print(arg + " ");
}
Main.main(args);
System.out.println("\n");
//Main.main(args);
apktool_241.loadClass("brut.apktool.Main").getMethod("main",String[].class).invoke(null,new Object[]{args});
File jarFile = new File(jarPath);
String name;
if (jarFile.getName().contains(".jar")) {
@ -246,7 +258,7 @@ public class SmaliUtils {
public boolean run = false;
public static StringBuffer error=new StringBuffer();
public void bale(String smaliPath, String path, SmaliApkToolsPath inter) {
String[] args = new String[]{"b", "-f", smaliPath, "-o", path};
String[] args = new String[]{"-r","b", "-f", smaliPath, "-o", path};
for (String string : args) {
System.out.print(string + " ");
}
@ -269,15 +281,17 @@ public class SmaliUtils {
}
}
System.setErr(old);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
System.setSecurityManager(new NoExitSecurityManager());
});
//System.setSecurityManager(new NoExitSecurityManager());
Main.main(args);
//Main.main(args);
apktool_234.loadClass("brut.apktool.Main").getMethod("main",String[].class).invoke(null,new Object[]{args});
if (inter != null) {
inter.smaliPath(path);
}

View File

@ -0,0 +1,10 @@
package com.qy.utils;
public class StringUtils {
public static boolean isEmpty(String str) {
if(str==null||str.trim().length()==0){
return true;
}
return false;
}
}

View File

@ -196,10 +196,10 @@ public class Tools {
}
}
try {
FileWriter writer=new FileWriter(file);
writer.write(data);
writer.flush();
writer.close();
OutputStream outputStream=new FileOutputStream(file);
outputStream.write(new String(data.getBytes(),StandardCharsets.UTF_8).getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}