├── README.md
├── pom.xml
└── src
└── main
└── java
├── META-INF
└── MANIFEST.MF
└── com
└── main.java
/README.md:
--------------------------------------------------------------------------------
1 | # BCELCode
2 | 对文件进行BCEL编码和解码
3 |
4 | 本工具基于Java开发,主要用来对指定文件进行编码和解码。由于每次更换payload时都要重新运行一次,所以就写了这款工具
5 | # 免责声明
6 |
7 | 依据中华人民共和国网络安全法第二十七条:任何个人和组织不得从事非法侵入他人网络、干扰他人网络正常功能、窃取网络数据等危害网络安全的活动;不得提供专门用于侵入网络、干扰网络正常功能及防护措施、窃取网络数据等危害网络安全活动的程序、工具;明知他人从事危害网络安全的活动的不得为其提供技术支持、广告推广、支付结算等帮助。
8 |
9 | 使用本工具则默认遵守网络安全法
10 | # 使用说明
11 |
12 | 显示帮助信息
13 | ``` Java -jar BCELCode.jar ```
14 |
15 | 
16 |
17 | 对文件进行编码,并在工具文件夹下生成txt文件
18 | ``` Java -jar BCELCode.jar -e FilePth ```
19 |
20 | 
21 |
22 | 对文件进行解码,并在工具文件夹下生成class文件
23 | ``` Java -jar BCELCode.jar -d FilePath ```
24 |
25 | 
26 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | BCELCode
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 7
13 | 7
14 |
15 |
16 |
17 |
18 | org.apache.bcel
19 | bcel
20 | 5.2
21 |
22 |
23 |
24 | commons-cli
25 | commons-cli
26 | 1.5.0
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/java/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: com.main
3 |
4 |
--------------------------------------------------------------------------------
/src/main/java/com/main.java:
--------------------------------------------------------------------------------
1 | package com;
2 |
3 | import org.apache.bcel.classfile.Utility;
4 | import org.apache.commons.cli.*;
5 |
6 | import java.io.File;
7 | import java.io.FileOutputStream;
8 | import java.io.PrintWriter;
9 | import java.nio.ByteBuffer;
10 | import java.nio.file.Files;
11 | import java.nio.file.Paths;
12 |
13 | class DtOptions {
14 |
15 | public static Options generateOp() {
16 | final Options options = new Options();
17 | options.addOption(new Option("e", "encode", true, "Enter the path of the file to be encoded"));
18 | options.addOption(new Option("d", "decode", true, "Enter the path to the file to decode"));
19 | options.addOption(new Option("h", "help", false, "Show this help"));
20 | return options;
21 | }
22 | }
23 |
24 | public class main {
25 |
26 | public static void main(String[] args) throws Exception {
27 | CommandLineParser parser = new DefaultParser();
28 | Options options = DtOptions.generateOp();
29 | CommandLine line = parser.parse(options, args);
30 | if (line.hasOption("e")) {
31 | encode(line.getOptionValue("e"));
32 | } else if (line.hasOption("d")) {
33 | decode(line.getOptionValue("d"));
34 | } else {
35 | HelpFormatter formatter = new HelpFormatter();
36 | formatter.printHelp("h", options);
37 | }
38 | }
39 |
40 | public static void encode(String filepath) {
41 | String filename = filepath.trim();
42 | filename = filename.substring(filename.lastIndexOf("/") + 1).split("\\.")[0] + ".txt";
43 | try {
44 |
45 | byte[] data = Files.readAllBytes(Paths.get(filepath));
46 | String str = Utility.encode(data, true);
47 | str = "$$BCEL$$" + str;
48 |
49 | PrintWriter pw = new PrintWriter(filename);
50 | pw.println(str);
51 | pw.close();
52 | System.out.println("BCEL encoding is successful and saved to " + filename);
53 | } catch (Exception e) {
54 | System.out.println("Error: " + e);
55 | }
56 | }
57 |
58 | public static void decode(String filepath) {
59 | String filename = filepath.trim();
60 | filename = filename.substring(filename.lastIndexOf("/") + 1).split("\\.")[0] + ".class";
61 | try {
62 |
63 | byte[] data = Files.readAllBytes(Paths.get(filepath));
64 | String str = new String(data, "utf-8").split("\n")[0];
65 | if (str.startsWith("$$BCEL$$") || str.startsWith("$$bcel$$")) {
66 | str = str.substring(8);
67 | }
68 | byte[] b = Utility.decode(str, true);
69 |
70 | ByteBuffer buffer = ByteBuffer.wrap(b);
71 | File file = new File(filename);
72 | FileOutputStream os = new FileOutputStream(file);
73 | os.write(b);
74 | os.close();
75 | System.out.println("BCEL decoded successfully and saved to " + filename);
76 |
77 | } catch (Exception e) {
78 | System.out.println("Error: " + e);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------