|
| 1 | +# code-encryptor-plus |
| 2 | + |
| 3 | +[](https://github.com/Y4Sec-Team/code-encryptor-plus/releases/latest) |
| 4 | + |
| 5 | + |
| 6 | +## Introduce |
| 7 | + |
| 8 | +This project uses `JNI` to encrypt bytecode and `JVMTI` to decrypt bytecode in order to protect code. |
| 9 | + |
| 10 | +It provides two `DLL` files: one for encryption and one for decryption. During actual execution, only the decryption `DLL` file is used. It supports custom keys and package names. |
| 11 | + |
| 12 | +The encrypted `Class` files become malformed and cannot be parsed. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +Apart from retaining the `Magic` part at the beginning, the rest becomes unrecognizable bytes. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +The encryption and decryption process involves two layers of encryption: the first layer in `C` and the second layer in `assembly`. Precompiled `Release` versions of `DLL/SO` files are included in the `Jar` package. |
| 23 | + |
| 24 | +Built-in support is for `JDK-8`, but other versions of `JDK` only require replacing the `JNI.h` header file and recompiling. The new version also supports both `Windows` and `Linux`. |
| 25 | + |
| 26 | +To encrypt your `Jar` package (specify the `Jar` package, the package name to encrypt, and the encryption key): |
| 27 | + |
| 28 | +```shell |
| 29 | +java -jar code-encryptor-plus.jar patch --jar your-jar.jar --package com.your.pack --key your-key |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +When exporting the decryption `DLL/SO` files, they will be placed in the default export directory, which is `code-encryptor-plus-temp`. It is not recommended to modify this directory. |
| 35 | + |
| 36 | +```shell |
| 37 | +java -jar code-encryptor-plus.jar export |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +Launching the Jar Package with Decryption DLL/SO: (Using the `-agentpath` Parameter) |
| 43 | + |
| 44 | +Please note that you must provide two parameters: `PACKAGE_NAME` and `KEY`. |
| 45 | +```shell |
| 46 | +java -agentpath:D:\abs-path\decrypter.dll=PACKAGE_NAME=com.your.pack,KEY=your-key --jar your-jar.jar |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +We also offer a straightforward GUI version that allows you to encrypt your chosen `Jar` file with a single click. (Available for Windows only) |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +## Features |
| 56 | + |
| 57 | +Compared to publicly available articles/code online, this project has several advantages and features: |
| 58 | + |
| 59 | +- The original article had a fixed package name, and users who want to encrypt their own package names need to recompile the `DLL`. |
| 60 | +- The original article used the same encryption and decryption `DLL`, making it easier to crack by simply calling encryption using `JNI`. |
| 61 | +- The original article's code was only at a demo level, making it difficult for users to test and use directly. |
| 62 | +- The original article did not include specific encryption algorithms; it only involved simple operations and needed enhancement. |
| 63 | +- The original article's code had some bugs and room for optimization. |
| 64 | + |
| 65 | +The current encryption and decryption algorithm includes: |
| 66 | + |
| 67 | +- Multiple bitwise operations implemented in assembly, byte swapping, and more. |
| 68 | +- Based on the `XXTEA` algorithm with multiple rounds of encryption. |
| 69 | +- Supports custom keys for further protection. |
| 70 | + |
| 71 | +## Building |
| 72 | + |
| 73 | +Compilation Environment: |
| 74 | +- Windows 11 / Ubuntu 22.04 |
| 75 | +- JDK 8 / Maven |
| 76 | +- MSVC + ml64 (Windows) / gcc + nasm (Linux) |
| 77 | +- CMake 3.x |
| 78 | +- Python 3.x |
| 79 | + |
| 80 | +The `native` directory is built using `cmake`, generating `dll` and `so` files that are then moved to the `resources` directory for Maven to build. |
| 81 | + |
| 82 | +## Notes |
| 83 | + |
| 84 | +This solution is not suitable for `SpringBoot` scenarios due to two issues: |
| 85 | +- `SpringBoot` does not allow the compression of `lib` dependencies (there are workarounds). |
| 86 | +- `SpringBoot` startup scanning will analyze `class` files, leading to errors when encrypted. |
| 87 | + |
| 88 | +Two solutions are available online, which you can refer to: |
| 89 | + |
| 90 | +Reference: https://zhuanlan.zhihu.com/p/545268749 |
| 91 | + |
| 92 | +Similarly, this encryption method cannot be used with code that scans `class` files during startup. |
| 93 | + |
| 94 | +## References |
| 95 | + |
| 96 | +Thanks to the following projects or articles for providing insights: |
| 97 | +- https://juejin.cn/post/6844903487784894477 |
| 98 | +- https://github.com/sea-boat/ByteCodeEncrypt |
| 99 | + |
0 commit comments