将java反编译代码生成一个exe可执行文件过程记录

1、编写java反编译代码

核心代码如下:

XCryptos.encryption()
        .from("/path/to/read/plaintext.jar")
        .use("io.xjar")
        .include("/io/xjar/**/*.class")
        .include("/mapper/**/*Mapper.xml")
        .exclude("/static/**/*")
        .exclude("/conf/*")
        .to("/path/to/save/encrypted.jar");

引用的pom如下:

<project>
    <!-- 设置 jitpack.io 仓库 -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    <!-- 添加 XJar 依赖 -->
    <dependencies>
        <dependency>
            <groupId>com.github.core-lib</groupId>
            <artifactId>xjar</artifactId>
            <version>4.0.2</version>
            <!-- <scope>test</scope> -->
        </dependency>
    </dependencies>
</project>

参考:https://github.com/core-lib/xjar

以上是找到的相应maven依赖来对JAR 进行安全加密。

在原有基础上新增了windows图形界面,参考代码如下:

package com.zy.java;

import io.xjar.XConstants;
import io.xjar.XKit;
import io.xjar.boot.XBoot;
import io.xjar.key.XKey;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.security.NoSuchAlgorithmException;

public class Practice{

    private static String password = "你的加密密码";
    private static JButton openItem, saveItem;
    private static FileDialog openDia, saveDia;// 定义“打开、保存”对话框
    private static String filePathOld;//旧文件路径
    private static String filePathNew;//新文件路径
    private static String fileName;//文件名
    static JFrame f = null;
    static JTextField locationText, typeText;

    public static void main(String[] args) {

        int gap = 5;
        f = new JFrame("加密程序");
        ImageIcon icon = new ImageIcon("src\\images\\2.ico");
        f.setIconImage(icon.getImage());// 给窗体设置图标方法
        f.setSize(550, 310);
        f.setLocation(200, 200);
        f.setLayout(null);

        JPanel pInput = new JPanel();
        pInput.setBounds(gap, gap, 520, 60);
        pInput.setLayout(new GridLayout(2, 3, gap, gap));


        JLabel location = new JLabel("JAR路径:");
        locationText = new JTextField(10);
        openItem = new JButton("选取");// 创建“打开"菜单项

        JLabel type = new JLabel("保存路径:");
        typeText = new JTextField(10);
        saveItem = new JButton("选取");// 创建“保存"菜单项

        openDia = new FileDialog(f, "打开", FileDialog.LOAD);
        saveDia = new FileDialog(f, "保存", FileDialog.SAVE);

        JButton b = new JButton("生成");

        pInput.add(location);
        pInput.add(locationText);
        pInput.add(openItem);
        pInput.add(type);
        pInput.add(typeText);
        pInput.add(saveItem);

        //文本域
        final JTextArea ta = new JTextArea();
        ta.setLineWrap(true);
        b.setBounds(220, 60 + 30, 80, 30);
        ta.setBounds(gap, 80 + 60, 523, 120);

        f.add(pInput);
        f.add(b);
        f.add(ta);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);

        myEvent();
        //鼠标监听
        b.addActionListener(new ActionListener() {
            boolean checkedpass = true;

            public void actionPerformed(ActionEvent e) {
                XKey xKey = null;
                System.out.println(" --- : "+fileName);
                String newPath = filePathNew+"\\"+fileName+"-xjar.jar";
                String oldPath = filePathOld;
                try {
                    xKey = XKit.key(password);
                    XBoot.encrypt(oldPath, newPath, xKey, XConstants.MODE_DANGER);
                    ta.append(" Success! ");
                } catch (NoSuchAlgorithmException eg) {
                    eg.printStackTrace();
                } catch (Exception eg) {
                    eg.printStackTrace();
                }
                checkedpass = true;
                checkEmpty(locationText, "JAR路径");
                checkEmpty(typeText, "保存路径");

                if (checkedpass) {
                    String model = "加密jar包保存路径 :%s";
                    String result = String.format(model, newPath);
                    ta.setText("");
                    ta.append(result);
                }

            }

            //检验是否为空
            private void checkEmpty(JTextField tf, String msg) {
                if (!checkedpass)
                    return;
                String value = tf.getText();
                if (value.length() == 0) {
                    JOptionPane.showMessageDialog(f, msg + " 不能为空");
                    tf.grabFocus();
                    checkedpass = false;
                }
            }
        });
    }

    //选取按钮监听
    private static void myEvent() {

        // 
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值