Browse Source

修复war包指定解密lib包时,不生效的问题

JustryDeng 3 năm trước cách đây
mục cha
commit
8ac05eff72

+ 13 - 10
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/Reverses.java

@@ -110,17 +110,20 @@ public class Reverses {
                     // 获取类所在的项目运行路径
                     String projectPath = protectionDomain.getCodeSource().getLocation().getPath();
                     try {
-                        projectPath = JarUtil.getRootPath(projectPath);
-                    } catch (ClassWinterException e) {
+                        projectPath = URLDecoder.decode(projectPath, StandardCharsets.UTF_8.name());
+                    } catch (UnsupportedEncodingException ex) {
+                        // ignore
+                    }
+                    
+                    // 如果不是强制指定解密该projectPath,那么解析其projectPath
+                    if (!isNeedTryDecrypt(decryptProjectPathPrefixSet, projectPath)) {
                         try {
-                            projectPath = URLDecoder.decode(projectPath, StandardCharsets.UTF_8.name());
-                        } catch (UnsupportedEncodingException ex) {
-                            // ignore
-                        }
-                        // 如果是不能识别的路径,那么看有没有强制指定解密该projectPath
-                        if (isNeedTryDecrypt(decryptProjectPathPrefixSet, projectPath)) {
-                            Logger.info(Reverses.class, "Ignore unknown path[" + e.getMessage() + "].Goon decrypt on projectPath -> " + projectPath);
-                        } else {
+                            projectPath = JarUtil.getRootPath(projectPath);
+                        } catch (ClassWinterException e) {
+                            return classfileBuffer;
+                        } catch (Exception e) {
+                            Logger.warn(Reverses.class, "JarUtil.getRootPath occur exception."
+                                    + " projectPath -> " + projectPath + ", e.getMessage() -> " + e.getMessage());
                             return classfileBuffer;
                         }
                     }

+ 0 - 5
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/util/JarUtil.java

@@ -389,11 +389,6 @@ public final class JarUtil {
      */
     public static String getRootPath(String projectPath) {
         Objects.requireNonNull(projectPath, "projectPath cannot be null.");
-        try {
-            projectPath = URLDecoder.decode(projectPath, StandardCharsets.UTF_8.name());
-        } catch (UnsupportedEncodingException e) {
-            // ignore
-        }
         if (projectPath.startsWith(Constant.JAR_PROTOCOL) || projectPath.startsWith(Constant.WAR_PROTOCOL)) {
             // jar协议/war协议的协议声明长度为4
             projectPath = projectPath.substring(4);