mirror of
https://github.com/pen4uin/java-memshell-generator.git
synced 2026-09-22 01:30:43 +08:00
61快乐
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>jmg</groupId>
|
||||
<artifactId>java-memshell-generator</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>jmg-custom</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>jmg</groupId>
|
||||
<artifactId>jmg-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -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