mirror of
https://github.com/pen4uin/java-memshell-generator.git
synced 2026-09-23 18:21:52 +08:00
61快乐
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package jmg.custom.generator;
|
||||
|
||||
import javassist.ClassClassPath;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import jmg.core.config.AbstractConfig;
|
||||
import jmg.core.generator.IShellGenerator;
|
||||
import jmg.core.util.CommonUtil;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.ServletRequestListener;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class CustomGenerator implements IShellGenerator {
|
||||
@Override
|
||||
public void initShell(AbstractConfig config) {
|
||||
File f;
|
||||
try {
|
||||
f = new File(config.getClassFilePath());
|
||||
if (!f.exists() || !f.isFile()) {
|
||||
return;
|
||||
}
|
||||
ClassPool classPool = ClassPool.getDefault();
|
||||
classPool.insertClassPath(new ClassClassPath(Filter.class));
|
||||
classPool.insertClassPath(new ClassClassPath(ServletRequestListener.class));
|
||||
classPool.makeInterface("org.springframework.web.servlet.AsyncHandlerInterceptor");
|
||||
classPool.makeInterface("org.springframework.web.servlet.HandlerInterceptor");
|
||||
String filePath = config.getClassFilePath();
|
||||
CtClass ctClass = classPool.makeClass(new DataInputStream(new FileInputStream(filePath)));
|
||||
config.setShellClassName(ctClass.getName());
|
||||
ctClass.detach();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] makeShell(AbstractConfig config) throws Exception {
|
||||
initShell(config);
|
||||
byte[] bytes = CommonUtil.getFileBytes(config.getClassFilePath());
|
||||
config.setShellBytes(bytes);
|
||||
config.setShellBytesLength(bytes.length);
|
||||
config.setShellGzipBase64String(CommonUtil.encodeBase64(CommonUtil.gzipCompress(bytes)));
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] modifyShell(String className, AbstractConfig config) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user