|
@@ -62,8 +62,33 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class AlreadyProtectedLibs_Test {
|
|
public class AlreadyProtectedLibs_Test {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
- String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
|
|
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ TimeUnit.SECONDS.sleep(3);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ // ignore
|
|
|
|
|
+ }
|
|
|
|
|
+ // 杀下进程(以防下一个测试方法启动jar时因为端口被占用启动不起来)
|
|
|
|
|
+ BashUtil.killProcessByPorts("8080");
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
|
|
+// test0();
|
|
|
|
|
+ test1();
|
|
|
|
|
+// test2();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 场景:
|
|
|
|
|
+ * 项目my-project-with-encrypted-lib-no-pwd.jar中的lib包
|
|
|
|
|
+ * encrypted-lib-no-pwd-1.0.0.jar本身就是被class-winter以自动生成的密码加密过了的
|
|
|
|
|
+ * 测试期望结果:
|
|
|
|
|
+ * 不用代理,直接(java -jar)启动jar包,会失败
|
|
|
|
|
+ */
|
|
|
|
|
+ private static void test0() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
// 加密
|
|
// 加密
|
|
|
EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
.originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-no-pwd.jar")
|
|
.originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-no-pwd.jar")
|
|
@@ -74,13 +99,75 @@ public class AlreadyProtectedLibs_Test {
|
|
|
.build();
|
|
.build();
|
|
|
String encryptedJar = encryptExecutor.process();
|
|
String encryptedJar = encryptExecutor.process();
|
|
|
System.out.println(encryptedJar);
|
|
System.out.println(encryptedJar);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 启动
|
|
|
|
|
+ BashUtil.runCmdAndPrint(String.format("java -jar %s", encryptedJar));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 场景:
|
|
|
|
|
+ * 项目my-project-with-encrypted-lib-no-pwd.jar中的lib包
|
|
|
|
|
+ * encrypted-lib-no-pwd-1.0.0.jar本身就是被class-winter以自动生成的密码加密过了的
|
|
|
|
|
+ * 测试期望结果:
|
|
|
|
|
+ * 正常启动项目my-project-with-encrypted-lib-no-pwd.jar,并
|
|
|
|
|
+ * 正常使用encrypted-lib-no-pwd-1.0.0.jar中的功能
|
|
|
|
|
+ */
|
|
|
|
|
+ private static void test1() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密
|
|
|
|
|
+ EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
|
|
+ .originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-no-pwd.jar")
|
|
|
|
|
+ // includePrefix字段是必填的,但是我们项目(my-project-with-encrypted-lib-no-pwd.jar)本身是没有混淆的,
|
|
|
|
|
+ // 只是其中的lib(encrypted-lib-no-pwd-1.0.0.jar)混淆了,我们项目是没必要进行解密的,所以这里值随便填什么都可以的
|
|
|
|
|
+ .includePrefix("non-exist")
|
|
|
|
|
+ .alreadyProtectedLibs("encrypted-lib-no-pwd-1.0.0.jar")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ String encryptedJar = encryptExecutor.process();
|
|
|
|
|
+ System.out.println(encryptedJar);
|
|
|
|
|
+
|
|
|
// (解密)启动
|
|
// (解密)启动
|
|
|
// 使用javaagent运行加密后的jar,测试
|
|
// 使用javaagent运行加密后的jar,测试
|
|
|
String javaagentArgs = "";
|
|
String javaagentArgs = "";
|
|
|
-// String javaagentArgs = "=debug=true,password=xxx";
|
|
|
|
|
|
|
+ // String javaagentArgs = "=debug=true,password=xxx";
|
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ TimeUnit.SECONDS.sleep(3);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ // ignore
|
|
|
|
|
+ }
|
|
|
|
|
+ // 杀下进程(以防下一个测试方法启动jar时因为端口被占用启动不起来)
|
|
|
|
|
+ BashUtil.killProcessByPorts("8080");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 场景:
|
|
|
|
|
+ * 项目my-project-with-encrypted-lib-no-pwd.jar中的lib包
|
|
|
|
|
+ * encrypted-lib-no-pwd-1.0.0.jar本身就是被class-winter以用户主动指定的密码加密过了的
|
|
|
|
|
+ * 测试期望结果:
|
|
|
|
|
+ * 正常启动项目my-project-with-encrypted-lib-no-pwd.jar,并
|
|
|
|
|
+ * 正常使用encrypted-lib-no-pwd-1.0.0.jar中的功能
|
|
|
|
|
+ */
|
|
|
|
|
+ private static void test2() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密
|
|
|
|
|
+ EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
|
|
+ .originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-no-pwd.jar")
|
|
|
|
|
+ // includePrefix字段是必填的,但是我们项目(my-project-with-encrypted-lib-no-pwd.jar)本身是没有混淆的,
|
|
|
|
|
+ // 只是其中的lib(encrypted-lib-no-pwd-1.0.0.jar)混淆了,我们项目是没必要进行解密的,所以这里值随便填什么都可以的
|
|
|
|
|
+ .includePrefix("non-exist")
|
|
|
|
|
+ .alreadyProtectedLibs("my-project-with-encrypted-lib-have-pwd.jar:qwer123~")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ String encryptedJar = encryptExecutor.process();
|
|
|
|
|
+ System.out.println(encryptedJar);
|
|
|
|
|
+
|
|
|
|
|
+ // (解密)启动
|
|
|
|
|
+ // 使用javaagent运行加密后的jar,测试
|
|
|
|
|
+ String javaagentArgs = "";
|
|
|
|
|
+ // String javaagentArgs = "=debug=true,password=xxx";
|
|
|
|
|
+ BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
TimeUnit.SECONDS.sleep(3);
|
|
TimeUnit.SECONDS.sleep(3);
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|