JadPlus

    科技2026-09-03  5

    import javax.swing.*; import javax.swing.filechooser.FileSystemView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; public class Client { JLabel consoleLabel; /** * 选择文件 * @return */ static File chooseFile(){ JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); //int returnValue = jfc.showOpenDialog(null); int returnValue = jfc.showSaveDialog(null); File path = null; if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = jfc.getSelectedFile(); //System.out.println(selectedFile.getAbsolutePath()); path = selectedFile; } return path; } /** * 选择文件夹 * @return */ static File chooseDir(){ JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); jfc.setDialogTitle("选择文件目录保存文件 "); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnValue = jfc.showSaveDialog(null); File path = null; if (returnValue == JFileChooser.APPROVE_OPTION) { if (jfc.getSelectedFile().isDirectory()) { //System.out.println("你选择的文件目录是: " + jfc.getSelectedFile()); path = jfc.getSelectedFile(); } } return path; } private static void placeComponents(JPanel panel) { /* 布局部分我们这边不多做介绍 * 这边设置布局为 null */ panel.setLayout(null); // 源文件路径 JLabel srcLabel = new JLabel("源文件:"); srcLabel.setBounds(10,20,80,25); panel.add(srcLabel); JTextField srcText = new JTextField(20); srcText.setBounds(100,20,500,25); panel.add(srcText); JButton srcButton = new JButton("选择"); srcButton.setBounds(650,20,80,25); srcButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File srcFile = chooseFile(); srcText.setText(srcFile.getPath()); } }); panel.add(srcButton); // 目标路径 JLabel destLabel = new JLabel("保存路径:"); destLabel.setBounds(10,60,80,25); panel.add(destLabel); JTextField destText = new JTextField(20); destText.setBounds(100,60,500,25); panel.add(destText); JButton destButton = new JButton("选择"); destButton.setBounds(650,60,80,25); destButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File destFile = chooseDir(); destText.setText(destFile.getPath()); } }); panel.add(destButton); // package包设置 JLabel packageLabel = new JLabel("package:"); packageLabel.setBounds(10,100,80,25); panel.add(packageLabel); JTextField packageText = new JTextField(20); packageText.setBounds(100,100,500,25); panel.add(packageText); //反编译按钮 JTextArea consoleArea = new JTextArea(); StringBuilder info = new StringBuilder(); JButton jadButton = new JButton("反编译"); jadButton.setBounds(100,140,80,25); jadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { info.append("开始解析....\n"); consoleArea.setText(info.toString()); File srcFile = new File(srcText.getText()); File destDir= new File(destText.getText()+"/"+srcFile.getName(). replace(".war", "").replace(".jar", "")); System.out.println("srcFile: " + srcFile); System.out.println("destDir: " + destDir); System.out.println("package: " + packageText.getText()); DecompileClass.unJar(srcFile, destDir.getPath(), packageText.getText()); try { Thread.sleep(1000); } catch (InterruptedException e1) { e1.printStackTrace(); } DecompileClass.traverseFolder(new File(destDir.getParent())); info.append("解析结束!\n"); consoleArea.setText(info.toString()); } }); panel.add(jadButton); //源码扫描按钮 // 控制台 JLabel consoleLabel = new JLabel("控制台:"); consoleLabel.setBounds(10,180,80,25); panel.add(consoleLabel); consoleArea.setBounds(100,180,600,360); panel.add(consoleArea); } public static void main(String[] args) { //new Client().chooseFile(); // 创建 JFrame 实例 JFrame frame = new JFrame("JadPlus, write by 仙草蜜"); // Setting the width and height of frame frame.setSize(800, 600); frame.setLocation(200, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /* 创建面板,这个类似于 HTML 的 div 标签 * 我们可以创建多个面板并在 JFrame 中指定位置 * 面板中我们可以添加文本字段,按钮及其他组件。 */ JPanel panel = new JPanel(); // 添加面板 frame.add(panel); /* * 调用用户定义的方法并添加组件到面板 */ placeComponents(panel); // 设置界面可见 frame.setVisible(true); } } import java.io.*; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class DecompileClass { /** * jar解压 * @param srcFile jar源文件 * @param destDirPath 解压后的目标文件夹 * @param packagePath 路径中的包名 * @throws RuntimeException 解压失败会抛出运行时异常 */ public static void unJar(File srcFile, String destDirPath, String packagePath) { // 判断源文件是否存在 if (!srcFile.exists()) { throw new RuntimeException(srcFile.getPath() + "所指文件不存在"); } // 开始解压 JarFile jarFile = null; try { jarFile = new JarFile(srcFile); Enumeration<?> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); System.out.println("解压:" + entry.getName()); // 如果是文件夹,就创建个文件夹 if (entry.isDirectory()) { String dirPath = destDirPath + "/" + entry.getName(); File dir = new File(dirPath); dir.mkdirs(); } else { // 如果是文件,就先创建一个文件,然后用io流把内容copy过去 String entryName = entry.getName(); File targetFile = new File(destDirPath + "/" + entryName); // 保证这个文件的父文件夹必须要存在 if(!targetFile.getParentFile().exists()){ targetFile.getParentFile().mkdirs(); } targetFile.createNewFile(); // 将压缩文件内容写入到这个文件中 InputStream is = jarFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(targetFile); int len; byte[] buf = new byte[1024]; while ((len = is.read(buf)) != -1) { fos.write(buf, 0, len); } // 关流顺序,先打开的后关闭 fos.close(); is.close(); // 如果jar包名有特定名称 if (null!=packagePath && !packagePath.equals("") && entryName.endsWith(".jar") && entryName.contains(packagePath)) { String destDir2 = new File(destDirPath).getParent() +"/"+ targetFile.getName().replace(".jar", ""); System.out.println("srcFile2: " + targetFile); System.out.println("destDir2: " + destDir2); System.out.println("package2: " + packagePath); unJar(targetFile, destDir2, packagePath); } } } } catch (Exception e) { throw new RuntimeException("文件解压发生错误", e); } finally { if(jarFile != null){ try { jarFile.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 执行系统命令 * @param command */ public static void execCmd(String command) { try { Process p = Runtime.getRuntime().exec(command); InputStream is = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); p.waitFor(); if (p.exitValue() != 0) { //说明命令执行失败 //可以进入到错误处理步骤中 System.out.println("命令执行错误"); } String s = null; while ((s = reader.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } /** * 便利文件夹下所有文件 * @param file */ public static void traverseFolder(File file) { File[] files = file.listFiles(); if (null != files && files.length > 0) { for (File file2 : files) { if (file2.isDirectory()) { traverseFolder(file2); } else { String fileName = file2.getAbsolutePath(); System.out.println("文件:" + fileName); if (fileName.endsWith("class")) { System.out.println("jad.exe -d "+file2.getParent()+" -s java "+fileName); execCmd("jad.exe -d "+file2.getParent()+" -s java "+fileName); } } } } } }
    Processed: 0.008, SQL: 9