|
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,36 @@ 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 (shellConfig.getShellType().endsWith(ShellType.DUBBO_SERVICE)) { |
| 67 | + String packageName = CommonUtil.getPackageName(shellToolConfig.getShellClassName()); |
| 68 | + String simpleName = CommonUtil.getSimpleName(shellToolConfig.getShellClassName()); |
| 69 | + String interfaceName = packageName + ".I" + simpleName; |
| 70 | + injectorConfig.setInjectorHelperClassName(interfaceName); |
| 71 | + injectorConfig.setHelperClassBytes(DubboServiceInterfaceHelperGenerator.getBytes(interfaceName, shellConfig)); |
| 72 | + shellBytes = ClassInterfaceUtils.addInterface(shellBytes, interfaceName); |
| 73 | + String urlPattern = injectorConfig.getUrlPattern(); |
| 74 | + if (Strings.CS.equalsAny(urlPattern, "/*", "/") |
| 75 | + || StringUtils.isBlank(urlPattern)) { |
| 76 | + injectorConfig.setUrlPattern(interfaceName); |
| 77 | + } |
| 78 | + } |
66 | 79 |
|
67 | 80 | if (ShellType.BYPASS_NGINX_WEBSOCKET.equals(shellConfig.getShellType()) |
68 | 81 | || ShellType.JAKARTA_BYPASS_NGINX_WEBSOCKET.equals(shellConfig.getShellType())) { |
69 | | - injectorConfig.setHelperClassBytes(WebSocketByPassHelperGenerator.getBytes(shellConfig, shellToolConfig)); |
| 82 | + String helperClassName = shellToolConfig.getShellClassName() + "$1"; |
| 83 | + injectorConfig.setInjectorHelperClassName(helperClassName); |
| 84 | + injectorConfig.setHelperClassBytes(WebSocketByPassHelperGenerator.getBytes(helperClassName, shellConfig, shellToolConfig)); |
70 | 85 | } |
71 | 86 |
|
| 87 | + injectorConfig.setInjectorClass(injectorClass); |
| 88 | + injectorConfig.setShellClassName(shellToolConfig.getShellClassName()); |
| 89 | + injectorConfig.setShellClassBytes(shellBytes); |
| 90 | + |
72 | 91 | InjectorGenerator injectorGenerator = new InjectorGenerator(shellConfig, injectorConfig); |
73 | 92 | byte[] injectorBytes = injectorGenerator.generate(); |
74 | 93 | if (shellConfig.isProbe() && !shellConfig.getShellType().startsWith(ShellType.AGENT)) { |
75 | 94 | ProbeConfig probeConfig = ProbeConfig.builder() |
76 | | - .shellClassName(injectorConfig.getInjectorClassName() + "1") |
| 95 | + .shellClassName(injectorConfig.getInjectorClassName() + "Wrapper") |
77 | 96 | .probeMethod(ProbeMethod.ResponseBody) |
78 | 97 | .probeContent(ProbeContent.Bytecode) |
79 | 98 | .targetJreVersion(shellConfig.getTargetJreVersion()) |
|
0 commit comments