diff --git a/src/com/qy/utils/AutoOutAPKTools.java b/src/com/qy/utils/AutoOutAPKTools.java index 3933df3..6d50d11 100644 --- a/src/com/qy/utils/AutoOutAPKTools.java +++ b/src/com/qy/utils/AutoOutAPKTools.java @@ -5,16 +5,16 @@ import com.qy.ui.ApkSignUi; import org.json.JSONObject; import javax.swing.*; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; +import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; +/** + * 在广州梦娱网络科技有限公司工作时所用的打包工具 + */ public class AutoOutAPKTools { private String gameId; - private Map channel; + private Map channel; private JSONObject manifestMap; private String appPath; private SmaliApkToolsPath inter; @@ -23,86 +23,93 @@ public class AutoOutAPKTools { this.gameId = gameId; this.channel = channel; } - public void setAppPath(String path){ - this.appPath=path; + + public void setAppPath(String path) { + this.appPath = path; } - public void setManifestMap(JSONObject map){ - this.manifestMap=map; + + public void setManifestMap(JSONObject map) { + this.manifestMap = map; } - public void start(SmaliApkToolsPath inter){ - this.inter=inter; + + public void start(SmaliApkToolsPath inter) { + this.inter = inter; outLog("复制游戏文件夹"); - String newAppPath=appPath+"_"+gameId+"_"+Tools.getRandomString(6); - Tools.copy_dir(appPath,newAppPath); - String oldPath=appPath; + String newAppPath = appPath + "_" + gameId + "_" + Tools.getRandomString(6); + Tools.copy_dir(appPath, newAppPath); + String oldPath = appPath; outLog("游戏游戏文件夹复制完成"); - appPath=newAppPath; + appPath = newAppPath; outLog("修改Manifest"); - alterManifest(new File(appPath+File.separator+"AndroidManifest.xml")); + alterManifest(new File(appPath + File.separator + "AndroidManifest.xml")); outLog("Manifest修改完成,开始生成assets"); outAssets(); outLog("生成完毕"); - new SmaliUtils().bale(appPath, appPath + File.separator + new File(oldPath).getName()+gameId, 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 + new File(oldPath).getName()+gameId); + inter.smaliPath(appPath + File.separator + new File(oldPath).getName() + gameId); } }); } - public void clear(){ + + public void clear() { Tools.deleteFiles(appPath); } - private void alterManifest(File manifest){ + + private void alterManifest(File manifest) { String tmp; StringBuilder str = new StringBuilder(); try { - List keys=new ArrayList<>(manifestMap.keySet()); + List keys = new ArrayList<>(manifestMap.keySet()); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(manifest), StandardCharsets.UTF_8)); while ((tmp = reader.readLine()) != null) { for (String key : keys) { - if(tmp.contains(key)){ - JSONObject json=manifestMap.getJSONObject(key); - tmp=tmp.replace(json.getString("key"),json.getString("value")); + if (tmp.contains(key)) { + JSONObject json = manifestMap.getJSONObject(key); + tmp = tmp.replace(json.getString("key"), json.getString("value")); } } str.append(tmp).append("\n"); } reader.close(); - Tools.saveConfig(manifest,str.toString()); + Tools.saveConfig(manifest, str.toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(str); } } - private void outAssets(){ - StringBuilder builder=new StringBuilder(); + + private void outAssets() { + StringBuilder builder = new StringBuilder(); builder.append("GAME_ID=").append(gameId).append("\n"); for (String key : channel.keySet()) { builder.append(key).append("=").append(channel.get(key)).append("\n"); } - Tools.saveConfig(new File(appPath+File.separator+"assets"+File.separator+"kusdkconf.ini"), + Tools.saveConfig(new File(appPath + File.separator + "assets" + File.separator + "kusdkconf.ini"), builder.toString()); } - private void outLog(String log){ + + private void outLog(String log) { System.out.println(log); } public static void main(String[] args) { - JSONObject json=new JSONObject(); - JSONObject pa=new JSONObject(); - JSONObject ji=new JSONObject(); - pa.put("key","${packagename}"); - pa.put("value","com.abc.def"); - ji.put("key","${JPUSH_KEY}"); - ji.put("value","aaabbccd"); - json.put("package=",pa); - json.put("JPUSH_APPKEY",ji); + JSONObject json = new JSONObject(); + JSONObject pa = new JSONObject(); + JSONObject ji = new JSONObject(); + pa.put("key", "${packagename}"); + pa.put("value", "com.abc.def"); + ji.put("key", "${JPUSH_KEY}"); + ji.put("value", "aaabbccd"); + json.put("package=", pa); + json.put("JPUSH_APPKEY", ji); - Map channel=new HashMap<>(); - channel.put("TOUTIAO_APP_ID","112345"); - AutoOutAPKTools tools=new AutoOutAPKTools( + Map channel = new HashMap<>(); + channel.put("TOUTIAO_APP_ID", "112345"); + AutoOutAPKTools tools = new AutoOutAPKTools( "123456", channel); tools.setAppPath("C:\\Users\\admin\\Documents\\游戏母包\\仙侠神域\\xianxiashenyu_29321_wozaijianghukey_xxsy_1627"); @@ -110,7 +117,7 @@ public class AutoOutAPKTools { tools.start(new SmaliApkToolsPath() { @Override public void smaliPath(String path) { - System.out.println("ok:"+path); + System.out.println("ok:" + path); } }); } diff --git a/src/com/qy/utils/SmaliUtils.java b/src/com/qy/utils/SmaliUtils.java index 31a9d2c..575b8d0 100755 --- a/src/com/qy/utils/SmaliUtils.java +++ b/src/com/qy/utils/SmaliUtils.java @@ -287,8 +287,8 @@ public class SmaliUtils { } } - }); - //System.setSecurityManager(new NoExitSecurityManager()); + }).start(); + System.setSecurityManager(new NoExitSecurityManager()); //Main.main(args); apktool_234.loadClass("brut.apktool.Main").getMethod("main",String[].class).invoke(null,new Object[]{args});