CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2015-8103/payloads/util/Serializables.java
Views: 11789
1
package ysoserial.payloads.util;
2
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.ObjectInputStream;
8
import java.io.ObjectOutputStream;
9
import java.io.OutputStream;
10
11
public class Serializables {
12
13
public static byte[] serialize(final Object obj) throws IOException {
14
final ByteArrayOutputStream out = new ByteArrayOutputStream();
15
serialize(obj, out);
16
return out.toByteArray();
17
}
18
19
public static void serialize(final Object obj, final OutputStream out) throws IOException {
20
final ObjectOutputStream objOut = new ObjectOutputStream(out);
21
objOut.writeObject(obj);
22
}
23
24
public static Object deserialize(final byte[] serialized) throws IOException, ClassNotFoundException {
25
final ByteArrayInputStream in = new ByteArrayInputStream(serialized);
26
return deserialize(in);
27
}
28
29
public static Object deserialize(final InputStream in) throws ClassNotFoundException, IOException {
30
final ObjectInputStream objIn = new ObjectInputStream(in);
31
return objIn.readObject();
32
}
33
34
}
35