-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
generator/src/main/java/com/reajason/javaweb/memshell/packer/SimpleJarPacker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.reajason.javaweb.memshell.packer; | ||
|
||
import com.reajason.javaweb.memshell.config.GenerateResult; | ||
import lombok.SneakyThrows; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarOutputStream; | ||
import java.util.jar.Manifest; | ||
|
||
/** | ||
* @author ReaJason | ||
* @since 2025/1/22 | ||
*/ | ||
public class SimpleJarPacker implements JarPacker { | ||
|
||
@Override | ||
@SneakyThrows | ||
public byte[] packBytes(GenerateResult generateResult) { | ||
String mainClass = generateResult.getInjectorClassName().replace('.', '/') + ".class"; | ||
String advisorClass = generateResult.getShellClassName().replace('.', '/') + ".class"; | ||
|
||
Manifest manifest = new Manifest(); | ||
manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
try (JarOutputStream targetJar = new JarOutputStream(byteArrayOutputStream, manifest)) { | ||
targetJar.putNextEntry(new JarEntry(mainClass)); | ||
targetJar.write(generateResult.getInjectorBytes()); | ||
targetJar.closeEntry(); | ||
|
||
targetJar.putNextEntry(new JarEntry(advisorClass)); | ||
targetJar.write(generateResult.getShellBytes()); | ||
targetJar.closeEntry(); | ||
} | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
} |