use VMOptions instead of System
This commit is contained in:
		| @@ -25,10 +25,10 @@ public class AgentMain { | |||||||
|                                 .on(ElementMatchers.named("openServer").and(ElementMatchers.takesArgument(0, String.class))))) |                                 .on(ElementMatchers.named("openServer").and(ElementMatchers.takesArgument(0, String.class))))) | ||||||
|                 .asTerminalTransformation() |                 .asTerminalTransformation() | ||||||
|  |  | ||||||
|                 .type(ElementMatchers.named("java.lang.System")) |                 .type(ElementMatchers.named("com.intellij.diagnostic.VMOptions")) | ||||||
|                 .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder |                 .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder | ||||||
|                         .visit(Advice.to(SystemAdvice.class) |                         .visit(Advice.to(VMOptionsAdvice.class) | ||||||
|                                 .on(ElementMatchers.named("getProperty")))) |                                 .on(ElementMatchers.named("getUserOptionsFile")))) | ||||||
|                 .asTerminalTransformation() |                 .asTerminalTransformation() | ||||||
|  |  | ||||||
|                 .installOn(inst); |                 .installOn(inst); | ||||||
|   | |||||||
| @@ -1,31 +0,0 @@ | |||||||
| package win.novice.li; |  | ||||||
|  |  | ||||||
| import net.bytebuddy.asm.Advice; |  | ||||||
|  |  | ||||||
| import java.util.Objects; |  | ||||||
|  |  | ||||||
| public class SystemAdvice { |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     //  System.getProperty |  | ||||||
|     @Advice.OnMethodExit |  | ||||||
|     public static void intercept(@Advice.Argument(0) Object x, @Advice.Return(readOnly = false) String r) throws Exception { |  | ||||||
|         if (Objects.equals(x, "jb.vmOptionsFile")) { |  | ||||||
|             RuntimeException exception = new RuntimeException(); |  | ||||||
|             int nullCnt = 0; |  | ||||||
|             boolean hasReflect = false; |  | ||||||
|             for (StackTraceElement element : exception.getStackTrace()) { |  | ||||||
|                 if (element.getFileName() == null) { |  | ||||||
|                     nullCnt += 1; |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
|                 if (element.getFileName().equals("Method.java")) { |  | ||||||
|                     hasReflect = true; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if (nullCnt >= 3 && hasReflect) { |  | ||||||
|                 r = null; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | package win.novice.li; | ||||||
|  |  | ||||||
|  | import net.bytebuddy.asm.Advice; | ||||||
|  |  | ||||||
|  | import java.nio.file.Path; | ||||||
|  |  | ||||||
|  | public class VMOptionsAdvice { | ||||||
|  |  | ||||||
|  |     @Advice.OnMethodExit | ||||||
|  |     public static void intercept(@Advice.Return(readOnly = false) Path r) throws Exception { | ||||||
|  |         RuntimeException e = new RuntimeException(); | ||||||
|  |         for (StackTraceElement stackTraceElement : e.getStackTrace()) { | ||||||
|  |             if (stackTraceElement.getFileName() == null){ | ||||||
|  |                 r = null; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user