From 862c17c90f4b2188507d5a51aaf0507bea267717 Mon Sep 17 00:00:00 2001 From: yutou Date: Fri, 9 Oct 2020 18:25:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=94=AF=E6=8C=81=E4=BF=9D=E5=AD=98=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E5=8F=82=E6=95=B0=20=E6=96=B0=E5=A2=9E=EF=BC=9A?= =?UTF-8?q?=E5=8F=8D=E7=BC=96=E8=AF=91=E6=89=93=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=8C=85=E7=BB=93=E6=9D=9F=E5=90=8E=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E6=98=AF=E5=90=A6=E8=BF=9B=E8=A1=8C=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=EF=BC=9Atext=5Fdialog=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BC=A0view=20=E4=BF=AE=E6=94=B9=EF=BC=9ATextToDalog=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8DTextToDialog=20=E4=BF=AE=E5=A4=8D=EF=BC=9A?= =?UTF-8?q?=E6=89=93=E5=8C=85=E5=B7=A5=E5=85=B7=E6=89=93=E5=8C=85=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5or=E5=8F=8D=E7=BC=96=E8=AF=91=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E9=97=AA=E9=80=80=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9A=E7=AD=BE=E5=90=8D=E5=B7=A5=E5=85=B7=E5=81=B6=E5=B0=94?= =?UTF-8?q?=E4=BC=9A=E5=8D=A1=E4=BD=8F=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=89=93=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=85=B3=E9=97=AD=E6=9C=AA=E6=9D=80=E6=AD=BB?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E5=AF=BC=E8=87=B4=E6=8C=82=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/qy/ui/ApkSignUi.java | 94 +++++++++++++++++++---- src/com/qy/ui/AppMain.java | 14 +--- src/com/qy/ui/ModifySdkUi.java | 8 +- src/com/qy/ui/OneWayTools.java | 12 +-- src/com/qy/ui/SMSToolsUi.java | 6 +- src/com/qy/ui/SmaliUi.java | 103 +++++++++++++++++++++----- src/com/qy/ui/TestAdSrc.java | 6 +- src/com/qy/ui/TextToDalog.java | 61 --------------- src/com/qy/ui/TextToDialog.java | 67 +++++++++++++++++ src/com/qy/utils/ApkSignTools.java | 10 ++- src/com/qy/utils/AutoRandomAdSDK.java | 4 - src/com/qy/utils/SmaliUtils.java | 78 ++++++++++++++++++- src/com/qy/utils/Tools.java | 21 ++++++ 13 files changed, 352 insertions(+), 132 deletions(-) delete mode 100755 src/com/qy/ui/TextToDalog.java create mode 100644 src/com/qy/ui/TextToDialog.java diff --git a/src/com/qy/ui/ApkSignUi.java b/src/com/qy/ui/ApkSignUi.java index 204875b..e07ab4b 100644 --- a/src/com/qy/ui/ApkSignUi.java +++ b/src/com/qy/ui/ApkSignUi.java @@ -1,16 +1,16 @@ package com.qy.ui; -import javax.swing.JFrame; -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JTextField; +import javax.swing.*; import com.qy.utils.ApkSignTools; +import com.qy.utils.Tools; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; import java.awt.event.ActionListener; import java.io.File; import java.awt.event.ActionEvent; +import java.util.*; public class ApkSignUi extends JFrame { public static void main(String[] args) { @@ -27,9 +27,10 @@ public class ApkSignUi extends JFrame { private ApkSignTools tools; private JLabel lblApkpath ; private JLabel lblSginpath; + private LinkedHashMap keyMap; public ApkSignUi() { - setTitle("\u7B7E\u540D\u5DE5\u5177v1.1"); + setTitle("\u7B7E\u540D\u5DE5\u5177v1.2"); setResizable(false); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // TODO Auto-generated constructor stub @@ -72,15 +73,18 @@ public class ApkSignUi extends JFrame { button.setBounds(36, 96, 105, 27); getContentPane().add(button); - JButton button_1 = new JButton("\u4F7F\u7528\u9ED8\u8BA4\u7B7E\u540D"); + JButton button_1 = new JButton("保存签名"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - File sign=new File("/media/yutou/_dde_data/AndroidKeys/langtian.jks"); - lblSginpath.setText(sign.getAbsolutePath()); - tools.setSignFile(sign); - txtName.setText("langtian"); - txtPass.setText("134679"); - txtSpass.setText("134679"); + + JSONObject key=new JSONObject(); + key.put("alias",txtName.getText()); + key.put("alias_password",txtSpass.getText()); + key.put("password",txtPass.getText()); + key.put("file",lblSginpath.getText()); + key.put("name",tools.getSignFile().getName()); + saveKey(key); + keyMap=loadKeys(); } }); button_1.setBounds(220, 96, 130, 27); @@ -108,6 +112,33 @@ public class ApkSignUi extends JFrame { getContentPane().add(txtName); txtName.setColumns(10); + keyMap=loadKeys(); + Vector adbList = new Vector<>(keyMap.keySet()); + JComboBox keysList=new JComboBox(adbList); + keysList.setBounds(157, 173, 200, 27); + keysList.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String key=adbList.get(keysList.getSelectedIndex()); + String tmp=keyMap.get(key); + if(!StringUtils.isEmpty(tmp)){ + JSONObject json=new JSONObject(tmp); + txtName.setText(json.getString("alias")); + txtSpass.setText(json.getString("alias_password")); + txtPass.setText(json.getString("password")); + lblSginpath.setText(json.getString("file")); + tools.setSignFile(new File(lblSginpath.getText())); + }else{ + txtName.setText("别名"); + txtSpass.setText("别名密码"); + txtPass.setText("密码"); + lblSginpath.setText(""); + tools.setSignFile(null); + } + } + }); + getContentPane().add(keysList); + JButton btnSign = new JButton("\u7B7E\u540D"); btnSign.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -116,17 +147,48 @@ public class ApkSignUi extends JFrame { tools.setSignKey(txtPass.getText()); if(tools.chack()) { if(tools.sign()) { - new TextToDalog("成功", "签名完成"); + new TextToDialog("成功", "签名完成"); }else{ - new TextToDalog("失败", "签名异常"); + new TextToDialog("失败", "签名异常"); } }else { - new TextToDalog("错误", "APK文件或签名文件不存在"); + new TextToDialog("错误", "APK文件或签名文件不存在"); } } }); btnSign.setBounds(263, 246, 105, 27); getContentPane().add(btnSign); setVisible(true); + + keyMap=loadKeys(); + } + + private void saveKey(JSONObject key) { + JSONObject keyJson= Tools.loadConfig(new File("keys.json")); + if(keyJson==null) + keyJson=new JSONObject(); + keyJson.put(key.getString("file"),key); + Tools.saveConfig(new File("keys.json"),keyJson.toString()); + + } + + public static LinkedHashMap loadKeys(){ + LinkedHashMap map=new LinkedHashMap<>(); + map.put("默认",""); + + JSONObject keyJson= Tools.loadConfig(new File("keys.json")); + if(keyJson==null) + { + keyJson=new JSONObject(); + } + Iterator keys=keyJson.keys(); + while (keys.hasNext()){ + String key=keys.next(); + map.put(keyJson.getJSONObject(key).getString("name")+"|"+new File(key).getParentFile().getName(), keyJson.getJSONObject(key).toString()); + } + return map; + } + + } diff --git a/src/com/qy/ui/AppMain.java b/src/com/qy/ui/AppMain.java index 39feb72..37982a5 100755 --- a/src/com/qy/ui/AppMain.java +++ b/src/com/qy/ui/AppMain.java @@ -2,9 +2,6 @@ package com.qy.ui; import java.awt.Color; import java.awt.Desktop; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -13,7 +10,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.security.Permission; import java.util.*; import java.util.Timer; @@ -21,12 +17,10 @@ import javax.swing.*; import javax.swing.border.LineBorder; import com.qy.utils.*; -import com.sun.javaws.exceptions.ExitException; import org.json.JSONArray; import org.json.JSONObject; import com.qy.Interfaces.SmaliApkToolsPath; -import org.json.JSONTokener; public class AppMain extends JFrame { private JList configList; @@ -250,7 +244,7 @@ public class AppMain extends JFrame { @Override public void mouseClicked(MouseEvent e) { if (configList.getSelectedIndex() < 0) { - new TextToDalog("警告", "列表未选择"); + new TextToDialog("警告", "列表未选择"); return; } json.put("switch", configList.getSelectedIndex() + 1 + ""); @@ -288,7 +282,7 @@ public class AppMain extends JFrame { @Override public void mouseClicked(MouseEvent e) { if (configList.getSelectedIndex() < 0) { - new TextToDalog("警告", "列表未选择"); + new TextToDialog("警告", "列表未选择"); return; } json.put("switch", configList.getSelectedIndex() + 1 + ""); @@ -439,7 +433,7 @@ public class AppMain extends JFrame { fileName += "_decrypt.jar"; } EncryptJar.FileData data = new EncryptJar().decrypt(file, fileName); - new TextToDalog("解码提示", data.toString()); + new TextToDialog("解码提示", data.toString()); //JarToBase.start(file.getAbsolutePath(), false); log.setText("已解码"); } @@ -654,7 +648,7 @@ public class AppMain extends JFrame { } public void autoPackageSdk() { - new AutoPackageSDK(path -> new TextToDalog("提示", String.format("打包完成%s", path)), version, packageName); + new AutoPackageSDK(path -> new TextToDialog("提示", String.format("打包完成%s", path)), version, packageName); } }); menu.add(autoSDK); diff --git a/src/com/qy/ui/ModifySdkUi.java b/src/com/qy/ui/ModifySdkUi.java index 53de251..5556fb0 100644 --- a/src/com/qy/ui/ModifySdkUi.java +++ b/src/com/qy/ui/ModifySdkUi.java @@ -13,8 +13,6 @@ import com.qy.utils.Tools; import javax.swing.JList; import java.io.File; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.Vector; @@ -78,7 +76,7 @@ public class ModifySdkUi extends JFrame{ @Override public void smaliPath(String path) { // TODO Auto-generated method stub - new TextToDalog("提示", "处理完毕,文件路径:"+path); + new TextToDialog("提示", "处理完毕,文件路径:"+path); } }); } @@ -90,14 +88,14 @@ public class ModifySdkUi extends JFrame{ @Override public void smaliPath(String path) { // TODO Auto-generated method stub - new TextToDalog("提示", "处理完毕,文件路径:"+path); + new TextToDialog("提示", "处理完毕,文件路径:"+path); } }); } }else { - new TextToDalog("警告", "未选择文件或未选择列表配置"); + new TextToDialog("警告", "未选择文件或未选择列表配置"); } } }); diff --git a/src/com/qy/ui/OneWayTools.java b/src/com/qy/ui/OneWayTools.java index fe36253..3a79f52 100755 --- a/src/com/qy/ui/OneWayTools.java +++ b/src/com/qy/ui/OneWayTools.java @@ -63,11 +63,11 @@ public class OneWayTools { + File.separator + "sdk" + File.separator + "c" + File.separator + "c.smali"); if (!activity.exists()) { System.out.println(activity.getAbsolutePath()); - new TextToDalog("警告", "Unit.smali文件不存在!"); + new TextToDialog("警告", "Unit.smali文件不存在!"); return; } if (!provider.exists()) { - new TextToDalog("警告", "c.smali文件不存在!"); + new TextToDialog("警告", "c.smali文件不存在!"); return; } @@ -169,10 +169,10 @@ public class OneWayTools { } catch (Exception e) { // TODO: handle exception e.printStackTrace(); - new TextToDalog("错误", "处理unit.smali文件失败:" + e.getMessage()); + new TextToDialog("错误", "处理unit.smali文件失败:" + e.getMessage()); return; } - new TextToDalog("警告", "Unit.smali文件没有包含指定代码,请手动检查"); + new TextToDialog("警告", "Unit.smali文件没有包含指定代码,请手动检查"); } private void updateProvider(String path) { @@ -210,9 +210,9 @@ public class OneWayTools { } catch (Exception e) { // TODO: handle exception e.printStackTrace(); - new TextToDalog("错误", "处理c.smali文件失败:" + e.getMessage()); + new TextToDialog("错误", "处理c.smali文件失败:" + e.getMessage()); return; } - new TextToDalog("警告", "c.smali文件没有包含指定代码,请手动检查"); + new TextToDialog("警告", "c.smali文件没有包含指定代码,请手动检查"); } } diff --git a/src/com/qy/ui/SMSToolsUi.java b/src/com/qy/ui/SMSToolsUi.java index 6a44688..ec3f81d 100755 --- a/src/com/qy/ui/SMSToolsUi.java +++ b/src/com/qy/ui/SMSToolsUi.java @@ -71,7 +71,7 @@ public class SMSToolsUi extends JFrame { SDKTools.start(new File("").getAbsolutePath()); btnNewButton.setText(path); btnNewButton.setEnabled(true); - new TextToDalog("提示", "计费SDK生成成功,请选择保存位置", new DalogAbs() { + new TextToDialog("提示", "计费SDK生成成功,请选择保存位置", new DalogAbs() { File sdk; @Override @@ -85,7 +85,7 @@ public class SMSToolsUi extends JFrame { File sdk_ = new File( sdk.getAbsolutePath() + "/" + "计费sdk" + SDKTools.version + ".zip"); SDKTools.buildSDK(sdk_); - new TextToDalog("完成", "任务已完成", new DalogAbs() { + new TextToDialog("完成", "任务已完成", new DalogAbs() { @Override public void onSuccess() { @@ -101,7 +101,7 @@ public class SMSToolsUi extends JFrame { }); } else { - new TextToDalog("错误", "已放弃本次任务"); + new TextToDialog("错误", "已放弃本次任务"); } } }); diff --git a/src/com/qy/ui/SmaliUi.java b/src/com/qy/ui/SmaliUi.java index 8a77548..2cd2b6c 100755 --- a/src/com/qy/ui/SmaliUi.java +++ b/src/com/qy/ui/SmaliUi.java @@ -4,31 +4,24 @@ import java.awt.Color; import java.awt.Desktop; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.Timer; -import java.util.TimerTask; -import java.util.Vector; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JTextField; -import javax.swing.SwingConstants; -import javax.swing.UIManager; +import javax.swing.*; import javax.swing.border.LineBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import com.qy.Interfaces.DalogAbs; import com.qy.Interfaces.SmaliApkToolsPath; +import com.qy.utils.ApkSignTools; import com.qy.utils.SmaliUtils; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; public class SmaliUi extends JFrame { /** @@ -56,6 +49,42 @@ public class SmaliUi extends JFrame { vector = new Vector<>(); fileList = new ArrayList<>(); timer = new Timer(); + addWindowListener(new WindowListener() {//监听关闭按钮,要取消timer,不然会一直线程挂起 + @Override + public void windowOpened(WindowEvent e) { + + } + + @Override + public void windowClosing(WindowEvent e) { + + } + + @Override + public void windowClosed(WindowEvent e) { + timer.cancel(); + } + + @Override + public void windowIconified(WindowEvent e) { + + } + + @Override + public void windowDeiconified(WindowEvent e) { + + } + + @Override + public void windowActivated(WindowEvent e) { + + } + + @Override + public void windowDeactivated(WindowEvent e) { + + } + }); initView(); } @@ -66,7 +95,7 @@ public class SmaliUi extends JFrame { // TODO: handle exception e.printStackTrace(); } - setTitle("Smali\u53CD\u7F16\u8BD1\u5DE5\u5177v1.2"); + setTitle("Smali\u53CD\u7F16\u8BD1\u5DE5\u5177v1.3"); // TODO Auto-generated constructor stub setSize(900, 673); getContentPane().setLayout(null); @@ -278,7 +307,7 @@ public class SmaliUi extends JFrame { public void run() { // TODO Auto-generated method stub if(jarPath.getText().trim().length()==0) { - new TextToDalog("警告", "没有选择目标文件"); + new TextToDialog("警告", "没有选择目标文件"); return; } utils.unPack(jarPath.getText(), new SmaliApkToolsPath() { @@ -309,11 +338,11 @@ public class SmaliUi extends JFrame { if(savePath.getText().trim().length()==0) { savePath.setText(smaliHome); lblInfo.setText("没有填写保存路径,默认保存在当前目录"); - new TextToDalog("警告", "没有填写保存路径,默认保存在当前目录"); + new TextToDialog("警告", "没有填写保存路径,默认保存在当前目录"); } if(jarPath.getText().trim().length()==0) { path="dex.zip"; - new TextToDalog("警告", "没有填写保存文件名,默认为dex.zip"); + new TextToDialog("警告", "没有填写保存文件名,默认为dex.zip"); }else { path=new File(jarPath.getText()).getName(); } @@ -324,7 +353,42 @@ public class SmaliUi extends JFrame { public void run() { // TODO Auto-generated method stub utils.bale(smaliPath.getText(), savePath.getText() + File.separator+path); + if(SmaliUtils.packageError){ + return; + } lblInfo.setText("打包完成,保存路径为:" + savePath.getText()); + LinkedHashMap keyMap=ApkSignUi.loadKeys(); + Vector adbList = new Vector(keyMap.keySet()); + JComboBox keysList=new JComboBox(adbList); + keysList.setBounds(157, 50, 200, 27); + new TextToDialog("选择签名", keysList, new DalogAbs() { + @Override + public void onSuccess() { + String key=adbList.get(keysList.getSelectedIndex()); + String tmp=keyMap.get(key); + if(!StringUtils.isEmpty(tmp)){ + lblInfo.setText("开始签名..."); + JSONObject json=new JSONObject(tmp); + ApkSignTools signTools=new ApkSignTools(); + signTools.setSignFile(new File(json.getString("file"))); + signTools.setApkFile(new File(savePath.getText()+ File.separator+path)); + signTools.setKeyStorePassword(json.getString("alias_password")); + signTools.setName(json.getString("alias")); + signTools.setSignKey(json.getString("password")); + if(signTools.sign()){ + try { + Desktop.getDesktop().open(new File(signTools.getApkFile().getAbsolutePath()+"_sign.apk").getParentFile()); + lblInfo.setText("签名完成"); + System.out.println("签名完成"); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + }else { + new TextToDialog("警告","签名失败"); + } + } + } + }); } }, 100); } @@ -382,6 +446,7 @@ public class SmaliUi extends JFrame { @Override public void smaliPath(String path) { lblInfo.setText("完成"); + } }); diff --git a/src/com/qy/ui/TestAdSrc.java b/src/com/qy/ui/TestAdSrc.java index 36524c7..de2f62b 100644 --- a/src/com/qy/ui/TestAdSrc.java +++ b/src/com/qy/ui/TestAdSrc.java @@ -41,7 +41,7 @@ public class TestAdSrc { File file = new File(obj.toString().substring(1, obj.toString().length() - 1)); System.out.println(file.getAbsolutePath()); if (!file.getName().endsWith(".apk")) { - new TextToDalog("警告", "并非一个apk文件:" + file.getAbsolutePath()); + new TextToDialog("警告", "并非一个apk文件:" + file.getAbsolutePath()); return true; } if (checkBox.isSelected()) { @@ -116,9 +116,9 @@ public class TestAdSrc { } } if(msg.equals("")){ - new TextToDalog("提示",file.getName()+"不包含已知广告源"); + new TextToDialog("提示",file.getName()+"不包含已知广告源"); }else{ - new TextToDalog("提示","已扫描到:"+msg); + new TextToDialog("提示","已扫描到:"+msg); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/com/qy/ui/TextToDalog.java b/src/com/qy/ui/TextToDalog.java deleted file mode 100755 index 60e2c91..0000000 --- a/src/com/qy/ui/TextToDalog.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.qy.ui; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JButton; -import javax.swing.JTextArea; - -import com.qy.Interfaces.DalogAbs; - -import javax.swing.JFrame; -import javax.swing.UIManager; - - -public class TextToDalog extends JFrame { - /** - * - */ - DalogAbs abs; - private static final long serialVersionUID = 1L; - public TextToDalog(String title,String text,DalogAbs abs) { - super(title); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.abs=abs; - initView(text); - } - /** - * @wbp.parser.constructor - */ - public TextToDalog(String title,String text) { - // TODO Auto-generated constructor stub - new TextToDalog(title, text,null); - } - public void initView(String text) { - // TODO Auto-generated constructor stub - setSize(636, 231); - getContentPane().setLayout(null); - - JTextArea lblNewLabel = new JTextArea(text); - lblNewLabel.setBackground(UIManager.getColor("Label.background")); - lblNewLabel.setEditable(false); - lblNewLabel.setLineWrap(true); - lblNewLabel.setBounds(42, 37, 438, 106); - getContentPane().add(lblNewLabel); - - - JButton btnOk = new JButton("ok"); - btnOk.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - TextToDalog.this.dispose(); - if(abs!=null) { - abs.onSuccess(); - } - } - }); - btnOk.setBounds(491, 144, 113, 27); - getContentPane().add(btnOk); - setVisible(true); - } -} diff --git a/src/com/qy/ui/TextToDialog.java b/src/com/qy/ui/TextToDialog.java new file mode 100644 index 0000000..f5676ad --- /dev/null +++ b/src/com/qy/ui/TextToDialog.java @@ -0,0 +1,67 @@ +package com.qy.ui; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.*; + +import com.qy.Interfaces.DalogAbs; + + +public class TextToDialog extends JFrame { + /** + * + */ + DalogAbs abs; + private static final long serialVersionUID = 1L; + public TextToDialog(String title, String text, DalogAbs abs) { + super(title); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.abs=abs; + initView(text,null); + } + public TextToDialog(String title, JComponent view,DalogAbs abs){ + super(title); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.abs=abs; + initView(null,view); + } + /** + * @wbp.parser.constructor + */ + public TextToDialog(String title, String text) { + // TODO Auto-generated constructor stub + new TextToDialog(title, text,null); + } + public void initView(String text,JComponent view) { + // TODO Auto-generated constructor stub + setSize(636, 231); + getContentPane().setLayout(null); + + if(view==null) { + JTextArea lblNewLabel = new JTextArea(text); + lblNewLabel.setBackground(UIManager.getColor("Label.background")); + lblNewLabel.setEditable(false); + lblNewLabel.setLineWrap(true); + lblNewLabel.setBounds(42, 37, 438, 106); + getContentPane().add(lblNewLabel); + }else{ + getContentPane().add(view); + } + + + JButton btnOk = new JButton("ok"); + btnOk.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + TextToDialog.this.dispose(); + if(abs!=null) { + abs.onSuccess(); + } + } + }); + btnOk.setBounds(491, 144, 113, 27); + getContentPane().add(btnOk); + setVisible(true); + } +} diff --git a/src/com/qy/utils/ApkSignTools.java b/src/com/qy/utils/ApkSignTools.java index cbd4e97..7630c4e 100644 --- a/src/com/qy/utils/ApkSignTools.java +++ b/src/com/qy/utils/ApkSignTools.java @@ -1,7 +1,9 @@ package com.qy.utils; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; public class ApkSignTools { @@ -29,7 +31,13 @@ public class ApkSignTools { + " -storepass " + keyStorePassword + " -signedjar \"" + apkFile.getAbsolutePath()+"_sign.apk" + "\" \"" + apkFile.getAbsolutePath() + "\" " + name; System.out.println(exec); try { - Runtime.getRuntime().exec(exec).waitFor(); + Process process=Runtime.getRuntime().exec(exec); + BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream())); + String tmp; + while ((tmp=reader.readLine())!=null){ + System.out.println(tmp); + } + reader.close(); return true; } catch (Exception e) { // TODO Auto-generated catch block diff --git a/src/com/qy/utils/AutoRandomAdSDK.java b/src/com/qy/utils/AutoRandomAdSDK.java index 17188d5..79573b6 100644 --- a/src/com/qy/utils/AutoRandomAdSDK.java +++ b/src/com/qy/utils/AutoRandomAdSDK.java @@ -1,8 +1,6 @@ package com.qy.utils; -import java.awt.Desktop; import java.io.*; -import java.sql.SQLOutput; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -13,7 +11,6 @@ import com.qy.ui.EditToDalog; import org.json.JSONArray; import org.json.JSONObject; -import com.qy.Interfaces.DalogAbs; /* 配置JSON格式: { @@ -47,7 +44,6 @@ import com.qy.Interfaces.DalogAbs; } */ import com.qy.Interfaces.SmaliApkToolsPath; -import com.qy.ui.TextToDalog; public class AutoRandomAdSDK { private File sdk; diff --git a/src/com/qy/utils/SmaliUtils.java b/src/com/qy/utils/SmaliUtils.java index ebbf346..b336c5e 100755 --- a/src/com/qy/utils/SmaliUtils.java +++ b/src/com/qy/utils/SmaliUtils.java @@ -1,18 +1,24 @@ package com.qy.utils; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.PrintWriter; +import java.io.*; +import java.nio.ByteBuffer; +import java.security.Permission; import java.util.ArrayList; 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; public class SmaliUtils { //private String str = ""; @@ -232,15 +238,45 @@ public class SmaliUtils { } public void bale(String path, String smaliPath) { + run=false; + packageError=false; bale(path, smaliPath, null); } + 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}; for (String string : args) { System.out.print(string + " "); } try { + run = true; + error=new StringBuffer(); + new Thread(new Runnable() { + @Override + public void run() { + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + PrintStream printStream = new PrintStream(outputStream); + PrintStream old=System.err; + System.setErr(printStream); + while (run) { + byte[] bs = outputStream.toByteArray(); + if (bs.length > 0) { + error.append(new String(outputStream.toByteArray())).append("\n"); + outputStream.reset(); + } + } + System.setErr(old); + } catch (Exception e) { + e.printStackTrace(); + } + + } + }).start(); + System.setSecurityManager(new NoExitSecurityManager()); + Main.main(args); if (inter != null) { inter.smaliPath(path); @@ -252,6 +288,8 @@ public class SmaliUtils { inter.smaliPath("error"); } } + System.setSecurityManager(null); + run = false; } List list; @@ -268,4 +306,36 @@ public class SmaliUtils { public void setFilter(List list) { this.list = list; } + public static boolean packageError=false; + public static class NoExitSecurityManager extends SecurityManager { + + public NoExitSecurityManager() { + } + + @Override + public void checkExit(int status) { + super.checkExit(status); + throw new SmaliUtils.ExitException(status); + } + + @Override + public void checkPermission(Permission perm) { + } + + @Override + public void checkPermission(Permission perm, Object context) { + } + + + } + + private static class ExitException extends SecurityException { + public ExitException(int status) { + System.out.println("print exit :" + status); + if(error.length()>0){ + packageError=true; + new TextToDialog("打包异常",error.toString()); + } + } + } } diff --git a/src/com/qy/utils/Tools.java b/src/com/qy/utils/Tools.java index 3644973..1ac3870 100755 --- a/src/com/qy/utils/Tools.java +++ b/src/com/qy/utils/Tools.java @@ -2,6 +2,7 @@ package com.qy.utils; import java.io.*; import java.nio.charset.StandardCharsets; +import java.rmi.server.ExportException; import java.util.Random; import java.util.jar.JarOutputStream; import java.util.zip.CRC32; @@ -184,7 +185,26 @@ public class Tools { } return true; } + public static void saveConfig(File file,String data){ + if(!file.exists()){ + try { + if(!file.createNewFile()){ + return; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + FileWriter writer=new FileWriter(file); + writer.write(data); + writer.flush(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } public static JSONObject loadConfig(File file) { JSONObject json = null; BufferedReader reader; @@ -202,6 +222,7 @@ public class Tools { while ((tmp = reader.readLine()) != null) { str += tmp; } + reader.close(); json = new JSONObject(str); } catch (Exception e) { // TODO Auto-generated catch block