|
1 | 1 | package com.reajason.javaweb.memshell; |
2 | 2 |
|
3 | 3 | import com.reajason.javaweb.GenerationException; |
| 4 | +import com.reajason.javaweb.asm.ClassInterfaceUtils; |
4 | 5 | import com.reajason.javaweb.memshell.config.InjectorConfig; |
5 | 6 | import com.reajason.javaweb.memshell.config.ShellConfig; |
6 | 7 | import com.reajason.javaweb.memshell.config.ShellToolConfig; |
| 8 | +import com.reajason.javaweb.memshell.generator.DubboServiceInterfaceHelperGenerator; |
7 | 9 | import com.reajason.javaweb.memshell.generator.InjectorGenerator; |
8 | 10 | import com.reajason.javaweb.memshell.generator.WebSocketByPassHelperGenerator; |
9 | 11 | import com.reajason.javaweb.memshell.server.AbstractServer; |
|
15 | 17 | import com.reajason.javaweb.utils.CommonUtil; |
16 | 18 | import org.apache.commons.codec.binary.Base64; |
17 | 19 | import org.apache.commons.lang3.StringUtils; |
| 20 | +import org.apache.commons.lang3.Strings; |
18 | 21 | import org.apache.commons.lang3.tuple.Pair; |
19 | 22 |
|
20 | 23 | import java.util.Map; |
@@ -60,20 +63,31 @@ public static MemShellResult generate(ShellConfig shellConfig, InjectorConfig in |
60 | 63 |
|
61 | 64 | byte[] shellBytes = ShellToolFactory.generateBytes(shellConfig, shellToolConfig); |
62 | 65 |
|
63 | | - injectorConfig.setInjectorClass(injectorClass); |
64 | | - injectorConfig.setShellClassName(shellToolConfig.getShellClassName()); |
65 | | - injectorConfig.setShellClassBytes(shellBytes); |
| 66 | + if (ShellType.DUBBO_SERVICE.equals(shellConfig.getShellType())) { |
| 67 | + String interfaceName = shellToolConfig.getShellClassName() + "$1"; |
| 68 | + injectorConfig.setHelperClassBytes(DubboServiceInterfaceHelperGenerator.getBytes(interfaceName, shellConfig)); |
| 69 | + shellBytes = ClassInterfaceUtils.addInterface(shellBytes, interfaceName); |
| 70 | + String urlPattern = injectorConfig.getUrlPattern(); |
| 71 | + if (Strings.CS.equalsAny(urlPattern, "/*", "/") |
| 72 | + || StringUtils.isBlank(urlPattern)) { |
| 73 | + injectorConfig.setUrlPattern(shellToolConfig.getShellClassName()); |
| 74 | + } |
| 75 | + } |
66 | 76 |
|
67 | 77 | if (ShellType.BYPASS_NGINX_WEBSOCKET.equals(shellConfig.getShellType()) |
68 | 78 | || ShellType.JAKARTA_BYPASS_NGINX_WEBSOCKET.equals(shellConfig.getShellType())) { |
69 | 79 | injectorConfig.setHelperClassBytes(WebSocketByPassHelperGenerator.getBytes(shellConfig, shellToolConfig)); |
70 | 80 | } |
71 | 81 |
|
| 82 | + injectorConfig.setInjectorClass(injectorClass); |
| 83 | + injectorConfig.setShellClassName(shellToolConfig.getShellClassName()); |
| 84 | + injectorConfig.setShellClassBytes(shellBytes); |
| 85 | + |
72 | 86 | InjectorGenerator injectorGenerator = new InjectorGenerator(shellConfig, injectorConfig); |
73 | 87 | byte[] injectorBytes = injectorGenerator.generate(); |
74 | 88 | if (shellConfig.isProbe() && !shellConfig.getShellType().startsWith(ShellType.AGENT)) { |
75 | 89 | ProbeConfig probeConfig = ProbeConfig.builder() |
76 | | - .shellClassName(injectorConfig.getInjectorClassName() + "1") |
| 90 | + .shellClassName(injectorConfig.getInjectorClassName() + "Wrapper") |
77 | 91 | .probeMethod(ProbeMethod.ResponseBody) |
78 | 92 | .probeContent(ProbeContent.Bytecode) |
79 | 93 | .targetJreVersion(shellConfig.getTargetJreVersion()) |
|
0 commit comments