mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
feat: support probe shell generation
This commit is contained in:
@@ -9,6 +9,9 @@ description = "Common Utilities for MemShellParty"
|
||||
version = rootProject.version
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(8)
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.reajason.javaweb;
|
||||
|
||||
import net.bytebuddy.jar.asm.ClassReader;
|
||||
import net.bytebuddy.jar.asm.ClassVisitor;
|
||||
import net.bytebuddy.jar.asm.ClassWriter;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
|
||||
+15
-1
@@ -9,10 +9,15 @@ import net.bytebuddy.jar.asm.Opcodes;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* 静态方法替换
|
||||
*
|
||||
* @author ReaJason
|
||||
*/
|
||||
public class MethodCallReplaceVisitorWrapper implements AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper {
|
||||
@@ -20,11 +25,20 @@ public class MethodCallReplaceVisitorWrapper implements AsmVisitorWrapper.ForDec
|
||||
private final String targetClassName;
|
||||
private final Set<String> replaceClassNames;
|
||||
|
||||
public MethodCallReplaceVisitorWrapper(String targetClassName, Set<String> replaceClassNames) {
|
||||
private MethodCallReplaceVisitorWrapper(String targetClassName, Set<String> replaceClassNames) {
|
||||
this.targetClassName = targetClassName.replace(".", "/");
|
||||
this.replaceClassNames = replaceClassNames.stream().map(s -> s.replace(".", "/")).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static AsmVisitorWrapper newInstance(String methodName, String className, String replaceClassName) {
|
||||
return new AsmVisitorWrapper.ForDeclaredMethods()
|
||||
.method(named(methodName),
|
||||
new MethodCallReplaceVisitorWrapper(
|
||||
className,
|
||||
Collections.singleton(replaceClassName))
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MethodVisitor wrap(@NotNull TypeDescription instrumentedType,
|
||||
|
||||
+2
-13
@@ -1,13 +1,9 @@
|
||||
package com.reajason.javaweb.buddy;
|
||||
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.asm.AsmVisitorWrapper;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -43,15 +39,8 @@ class MethodCallReplaceVisitorWrapperTest {
|
||||
DynamicType.Unloaded<TargetClass> dynamicType = new ByteBuddy()
|
||||
.redefine(TargetClass.class)
|
||||
.name(newClassName)
|
||||
.visit(new AsmVisitorWrapper
|
||||
.ForDeclaredMethods()
|
||||
.method(named("targetMethod"),
|
||||
new MethodCallReplaceVisitorWrapper(
|
||||
newClassName,
|
||||
Collections.singleton(ExternalClass.class.getName())
|
||||
)
|
||||
)
|
||||
)
|
||||
.visit(MethodCallReplaceVisitorWrapper.newInstance(
|
||||
"targetMethod", newClassName, ExternalClass.class.getName()))
|
||||
.make();
|
||||
Class<?> redefinedClass = dynamicType.load(MethodCallReplaceVisitorWrapperTest.class.getClassLoader())
|
||||
.getLoaded();
|
||||
|
||||
Reference in New Issue
Block a user