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

@ -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();
}