Ver código fonte

补充xml混淆支持

JustryDeng 4 anos atrás
pai
commit
eb648f8a4f

+ 3 - 3
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/Forward.java

@@ -28,7 +28,7 @@ public class Forward {
         String excludePrefix = parseValueByPrefixFromTail("excludePrefix=", args);
         String includeXmlPrefix = parseValueByPrefixFromTail("includeXmlPrefix=", args);
         String excludeXmlPrefix = parseValueByPrefixFromTail("excludeXmlPrefix=", args);
-        String toCleanChildElementName = parseValueByPrefixFromTail("toCleanChildElementName=", args);
+        String toCleanXmlChildElementName = parseValueByPrefixFromTail("toCleanXmlChildElementName=", args);
         String finalName = parseValueByPrefixFromTail("finalName=", args);
         String password = parseValueByPrefixFromTail("password=", args);
         String includeLibs = parseValueByPrefixFromTail("includeLibs=", args);
@@ -43,7 +43,7 @@ public class Forward {
         Logger.debug(Forward.class, "You input arg excludePrefix -> " + excludePrefix);
         Logger.debug(Forward.class, "You input arg includeXmlPrefix -> " + includeXmlPrefix);
         Logger.debug(Forward.class, "You input arg excludeXmlPrefix -> " + excludeXmlPrefix);
-        Logger.debug(Forward.class, "You input arg toCleanChildElementName -> " + toCleanChildElementName);
+        Logger.debug(Forward.class, "You input arg toCleanXmlChildElementName -> " + toCleanXmlChildElementName);
         Logger.debug(Forward.class, "You input arg finalName -> " + finalName);
         Logger.debug(Forward.class, "You input arg password -> " + password);
         Logger.debug(Forward.class, "You input arg includeLibs -> " + includeLibs);
@@ -59,7 +59,7 @@ public class Forward {
                 .excludePrefix(excludePrefix)
                 .includeXmlPrefix(includeXmlPrefix)
                 .excludeXmlPrefix(excludeXmlPrefix)
-                .toCleanChildElementName(toCleanChildElementName)
+                .toCleanXmlChildElementName(toCleanXmlChildElementName)
                 .finalName(finalName)
                 .password(password)
                 .includeLibs(includeLibs)

+ 4 - 1
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/executor/DecryptExecutor.java

@@ -121,7 +121,7 @@ public class DecryptExecutor {
                         .forEach(info -> {
                             int idx = info.indexOf("=");
                             if (idx > 0) {
-                                // libDirRelativePath形如: META-INF/winter/abc-1.0.0_jar/
+                                // libDirRelativePath形如: META-INF/winter/classes/abc-1.0.0_jar/
                                 String libDirRelativePath = info.substring(0, idx);
                                 String checklist = info.substring(idx + 1);
                                 if (StrUtil.isBlank(checklist)) {
@@ -256,6 +256,9 @@ public class DecryptExecutor {
     public static Map<String, Pair<byte[], byte[]>> unMaskNonClassFiles(String zipFilePath, char[] password) throws IOException {
         final File zipFile = new File(zipFilePath);
         byte[] nonClassFileChecklistBytes = IOUtil.readFileFromWorkbenchRoot(zipFile, Constant.ALREADY_ENCRYPTED_NON_CLASS_FILE_CHECKLIST_SAVE_FILE);
+        if (nonClassFileChecklistBytes == null) {
+            return new HashMap<>(1);
+        }
         String nonClassFileChecklist = new String(nonClassFileChecklistBytes, StandardCharsets.UTF_8);
         Logger.debug(DecryptExecutor.class, "nonClassFileChecklist -> " + nonClassFileChecklist);
         if (StrUtil.isBlank(nonClassFileChecklist)) {

+ 11 - 11
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/executor/EncryptExecutor.java

@@ -122,7 +122,7 @@ public class EncryptExecutor {
     /**
      * xml中要清除的(根节点的)子节点名称
      */
-    private final Set<String> toCleanChildElementNameSet;
+    private final Set<String> toCleanXmlChildElementNameSet;
 
     
     /**
@@ -199,7 +199,7 @@ public class EncryptExecutor {
     
     private EncryptExecutor(String originJarOrWar, boolean originIsJar, String finalName, String targetRootDir,
                             String targetLibDir, String targetClassesDir, String password,
-                            Set<String> includeXmlPrefixSet, Set<String> excludeXmlPrefixSet, Set<String> toCleanChildElementNameSet,
+                            Set<String> includeXmlPrefixSet, Set<String> excludeXmlPrefixSet, Set<String> toCleanXmlChildElementNameSet,
                             Set<String> includePrefixSet, Set<String> excludePrefixSet, Set<String> includeLibSet,
                             Set<Pair<String, String>> alreadyProtectedLibSet, String supportFile) {
         this.originJarOrWar = originJarOrWar;
@@ -211,7 +211,7 @@ public class EncryptExecutor {
         this.password = password;
         this.includeXmlPrefixSet = includeXmlPrefixSet;
         this.excludeXmlPrefixSet = excludeXmlPrefixSet;
-        this.toCleanChildElementNameSet = toCleanChildElementNameSet;
+        this.toCleanXmlChildElementNameSet = toCleanXmlChildElementNameSet;
         this.includePrefixSet = includePrefixSet;
         this.excludePrefixSet = excludePrefixSet;
         this.includeLibSet = includeLibSet;
@@ -345,7 +345,7 @@ public class EncryptExecutor {
         // 清空原xml文件的关键节点
         for (String zipEntryName : encryptNonClassFileSet) {
             byte[] bytes = IOUtil.readFileFromWorkbenchRoot(targetRootDirFile, zipEntryName);
-            String cleanedXml = clearXml(new String(bytes, StandardCharsets.UTF_8), Constant.XML_PADDING_COMMENT, toCleanChildElementNameSet);
+            String cleanedXml = clearXml(new String(bytes, StandardCharsets.UTF_8), "\n\t\t\t" + Constant.TIPS + "\n\t\t\t" + Constant.SEAL, toCleanXmlChildElementNameSet);
             IOUtil.writeContentToFile(cleanedXml, new File(targetRootDir, zipEntryName));
         }
     }
@@ -908,7 +908,7 @@ public class EncryptExecutor {
                 ", excludePrefixSet=" + excludePrefixSet +
                 ", includeXmlPrefixSet=" + includeXmlPrefixSet +
                 ", excludeXmlPrefixSet=" + excludeXmlPrefixSet +
-                ", toCleanChildElementNameSet=" + toCleanChildElementNameSet +
+                ", toCleanChildElementNameSet=" + toCleanXmlChildElementNameSet +
                 ", includeLibSet=" + includeLibSet +
                 ", alreadyProtectedLibSet=" + alreadyProtectedLibSet +
                 '}';
@@ -937,7 +937,7 @@ public class EncryptExecutor {
         
         private String excludeXmlPrefix;
         
-        private String toCleanChildElementName;
+        private String toCleanXmlChildElementName;
         
         private String includeLibs;
         
@@ -984,8 +984,8 @@ public class EncryptExecutor {
             return this;
         }
         
-        public Builder toCleanChildElementName(String toCleanChildElementName) {
-            this.toCleanChildElementName = toCleanChildElementName;
+        public Builder toCleanXmlChildElementName(String toCleanXmlChildElementName) {
+            this.toCleanXmlChildElementName = toCleanXmlChildElementName;
             return this;
         }
         
@@ -1104,10 +1104,10 @@ public class EncryptExecutor {
             // xml相关参数解析
             Set<String> includeXmlPrefixSet = StrUtil.strToSet(includeXmlPrefix);
             Set<String> excludeXmlPrefixSet = StrUtil.strToSet(excludeXmlPrefix);
-            toCleanChildElementName = StrUtil.isBlank(toCleanChildElementName) ? Constant.DEFAULT_XML_NODE_NAMES : toCleanChildElementName;
-            Set<String> toCleanChildElementNameSet = StrUtil.strToSet(toCleanChildElementName);
+            toCleanXmlChildElementName = StrUtil.isBlank(toCleanXmlChildElementName) ? Constant.DEFAULT_XML_NODE_NAMES : toCleanXmlChildElementName;
+            Set<String> toCleanXmlChildElementNameSet = StrUtil.strToSet(toCleanXmlChildElementName);
             return new EncryptExecutor(this.originJarOrWar, originIsJar, this.finalName, targetRootDir, targetLibDir, targetClassesDir,
-                    password, includeXmlPrefixSet, excludeXmlPrefixSet, toCleanChildElementNameSet, includePrefixSet, excludePrefixSet, includeLibSet, alreadyProtectedLibSet, this.supportFile);
+                    password, includeXmlPrefixSet, excludeXmlPrefixSet, toCleanXmlChildElementNameSet, includePrefixSet, excludePrefixSet, includeLibSet, alreadyProtectedLibSet, this.supportFile);
         }
     
         /**

+ 1 - 6
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/util/Constant.java

@@ -29,11 +29,6 @@ public interface Constant {
      */
     String DEFAULT_XML_NODE_NAMES = "resultMap,sql,insert,update,delete,select";
     
-    /**
-     * xml被清除后,添加的注释填充
-     */
-    String XML_PADDING_COMMENT = "\n\t\t\t" + TIPS + "\n\t\t\t" + SEAL;
-    
     /**
      * 解压jar/war包时,临时目录后缀名
      */
@@ -97,7 +92,7 @@ public interface Constant {
     /**
      * 汇总记录项目中那些本身就已经被class-winter混淆了的lib的checklist
      */
-    String CHECKLIST_OF_ALL_LIBS = "META-INF/winter/checklist-of-all-libs.winter";
+    String CHECKLIST_OF_ALL_LIBS = DEFAULT_ENCRYPTED_CLASSES_SAVE_DIR + "checklist-of-all-libs.winter";
     
     /**
      * 当用户不主动指定密码时,class_winter会自动生成加密密码,并存至此处

+ 3 - 3
class-winter-maven-plugin/src/main/java/winter/com/ideaaedi/classwinter/plugin/ClassWinterPlugin.java

@@ -48,7 +48,7 @@ public class ClassWinterPlugin extends AbstractMojo {
     private String excludeXmlPrefix;
     
     @Parameter
-    private String toCleanChildElementName;
+    private String toCleanXmlChildElementName;
     
     @Parameter
     private String includeLibs;
@@ -76,7 +76,7 @@ public class ClassWinterPlugin extends AbstractMojo {
         Logger.debug("You config arg excludePrefix -> " + excludePrefix);
         Logger.debug("You config arg includeXmlPrefix -> " + includeXmlPrefix);
         Logger.debug("You config arg excludeXmlPrefix -> " + excludeXmlPrefix);
-        Logger.debug("You config arg toCleanChildElementName -> " + toCleanChildElementName);
+        Logger.debug("You config arg toCleanXmlChildElementName -> " + toCleanXmlChildElementName);
         Logger.debug("You config arg finalName -> " + finalName);
         Logger.debug("You config arg password -> " + password);
         Logger.debug("You config arg includeLibs -> " + includeLibs);
@@ -96,7 +96,7 @@ public class ClassWinterPlugin extends AbstractMojo {
                 .excludePrefix(excludePrefix)
                 .includeXmlPrefix(includeXmlPrefix)
                 .excludeXmlPrefix(excludeXmlPrefix)
-                .toCleanChildElementName(toCleanChildElementName)
+                .toCleanXmlChildElementName(toCleanXmlChildElementName)
                 .includeLibs(includeLibs)
                 .alreadyProtectedLibs(alreadyProtectedLibs)
                 .supportFile(supportFile)