|
@@ -0,0 +1,180 @@
|
|
|
|
|
+package winter.com.ideaaedi.classwinter;
|
|
|
|
|
+
|
|
|
|
|
+import winter.com.ideaaedi.classwinter.author.JustryDeng;
|
|
|
|
|
+import winter.com.ideaaedi.classwinter.executor.EncryptExecutor;
|
|
|
|
|
+import winter.com.ideaaedi.classwinter.util.BashUtil;
|
|
|
|
|
+import winter.com.ideaaedi.classwinter.util.PathUtil;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 这里只讲war包进行混淆, 需要执行使用web容器(如tomcat)启动war包
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author {@link JustryDeng}
|
|
|
|
|
+ * @since 2021/6/12 14:34:45
|
|
|
|
|
+ */
|
|
|
|
|
+public class War_Test {
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ // 杀下进程(以保证端口没有被占用)
|
|
|
|
|
+ BashUtil.killProcessByPorts("8080");
|
|
|
|
|
+// test0();
|
|
|
|
|
+ test1();
|
|
|
|
|
+// test2();
|
|
|
|
|
+// test3();
|
|
|
|
|
+// test4();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第一个war
|
|
|
|
|
+ *
|
|
|
|
|
+ * 输出:
|
|
|
|
|
+ * 请使用web容器(如tomcat)启动war包:E:/Git/Repository/class-winter/class-winter-core/target/test-classes/war-project-encrypted.war
|
|
|
|
|
+ * 其中参数附加 -javaagent:class-winter-core.jar
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test0() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "war-project.war";
|
|
|
|
|
+ String includePrefix = "com";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedWar = originJarOrWar.replace(".war", "-encrypted.war");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ System.err.println("请使用web容器(如tomcat)启动war包:" + encryptedWar);
|
|
|
|
|
+ System.err.println("其中参数附加 -javaagent:class-winter-core.jar");
|
|
|
|
|
+ // System.err.println("其中参数附加 -javaagent:class-winter-core.jar=debug=true,password=pwd123");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第二个war
|
|
|
|
|
+ *
|
|
|
|
|
+ * 输出:
|
|
|
|
|
+ * 请使用web容器(如tomcat)启动war包:E:/Git/Repository/class-winter/class-winter-core/target/test-classes/my-project-with-normal-lib-encrypted.war
|
|
|
|
|
+ * 其中参数附加 -javaagent:class-winter-core.jar=password=123456
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test1() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "my-project-with-normal-lib.war";
|
|
|
|
|
+ String includePrefix = "com";
|
|
|
|
|
+ String password = "123456";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ + " password=" + password
|
|
|
|
|
+ + " debug=" + true
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedWar = originJarOrWar.replace(".war", "-encrypted.war");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ System.err.println("请使用web容器(如tomcat)启动war包:" + encryptedWar);
|
|
|
|
|
+ System.err.println("其中参数附加 -javaagent:class-winter-core.jar=password=" + password);
|
|
|
|
|
+ // System.err.println("其中参数附加 -javaagent:class-winter-core.jar=debug=true,password=pwd123");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第三个war
|
|
|
|
|
+ *
|
|
|
|
|
+ * 输出:
|
|
|
|
|
+ * 请使用web容器(如tomcat)启动war包:E:/Git/Repository/class-winter/class-winter-core/target/test-classes/my-project-with-encrypted-lib-no-pwd-encrypted.war
|
|
|
|
|
+ * 其中参数附加 -javaagent:class-winter-core.jar=password=oop857857
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test2() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "my-project-with-encrypted-lib-no-pwd.war";
|
|
|
|
|
+ String includePrefix = "com";
|
|
|
|
|
+ String alreadyProtectedLibs = "encrypted-lib-no-pwd-1.0.0.jar";
|
|
|
|
|
+ String password = "oop857857";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ + " alreadyProtectedLibs=" + alreadyProtectedLibs
|
|
|
|
|
+ + " password=" + password
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedWar = originJarOrWar.replace(".war", "-encrypted.war");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ System.err.println("请使用web容器(如tomcat)启动war包:" + encryptedWar);
|
|
|
|
|
+ System.err.println("其中参数附加 -javaagent:class-winter-core.jar=password=" + password);
|
|
|
|
|
+ // System.err.println("其中参数附加 -javaagent:class-winter-core.jar=debug=true,password=pwd123");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第四个war
|
|
|
|
|
+ *
|
|
|
|
|
+ * 输出:
|
|
|
|
|
+ * 请使用web容器(如tomcat)启动war包:E:/Git/Repository/class-winter/class-winter-core/target/test-classes/my-project-with-encrypted-lib-have-pwd-encrypted.war
|
|
|
|
|
+ * 其中参数附加 -javaagent:class-winter-core.jar=password=yiyakaka
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test3() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "my-project-with-encrypted-lib-have-pwd.war";
|
|
|
|
|
+ String includePrefix = "com";
|
|
|
|
|
+ String alreadyProtectedLibs = "encrypted-lib-have-pwd-1.0.0.jar:qwer123~";
|
|
|
|
|
+ String password = "yiyakaka";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ + " alreadyProtectedLibs=" + alreadyProtectedLibs
|
|
|
|
|
+ + " password=" + password
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedWar = originJarOrWar.replace(".war", "-encrypted.war");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ System.err.println("请使用web容器(如tomcat)启动war包:" + encryptedWar);
|
|
|
|
|
+ System.err.println("其中参数附加 -javaagent:class-winter-core.jar=password=" + password);
|
|
|
|
|
+ // System.err.println("其中参数附加 -javaagent:class-winter-core.jar=debug=true,password=pwd123");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 第五个war
|
|
|
|
|
+ *
|
|
|
|
|
+ * 输出:
|
|
|
|
|
+ * 请使用web容器(如tomcat)启动war包:E:/Git/Repository/class-winter/class-winter-core/target/test-classes/jd.war
|
|
|
|
|
+ * 其中参数附加 -javaagent:class-winter-core.jar=password=pwd12345
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test4() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AllTest.class);
|
|
|
|
|
+ EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
|
|
+ .originJarOrWar(projectRootDir + "my-project-with-encrypted-lib-have-pwd.war")
|
|
|
|
|
+ .includePrefix("com.szlaozicl,com.aspire.ssm,org.springframework.aop.target.dynamic,com.fasterxml.jackson")
|
|
|
|
|
+ .excludePrefix("com.aspire.ssm.config,com.aspire.ssm.util.Person")
|
|
|
|
|
+ .finalName("jd")
|
|
|
|
|
+ .password("pwd12345")
|
|
|
|
|
+ .includeLibs("spring-aop-5.2.7.RELEASE.jar,jackson-core-2.10.4.jar")
|
|
|
|
|
+ .tips("方法已经被class-winter加密保护了,请不要直接使用java -jar xxx.jar启动项目,请使用java -javaagent:xxx.jar -jar xxx.jar启动项目.")
|
|
|
|
|
+ .alreadyProtectedLibs("encrypted-lib-have-pwd-1.0.0.jar:qwer123~")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedWar = encryptExecutor.process();
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ System.err.println("请使用web容器(如tomcat)启动war包:" + encryptedWar);
|
|
|
|
|
+ System.err.println("其中参数附加 -javaagent:class-winter-core.jar=password=pwd12345");
|
|
|
|
|
+ // System.err.println("其中参数附加 -javaagent:class-winter-core.jar=debug=true,password=pwd123");
|
|
|
|
|
+ System.err.println();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|