import java.io.Serializable;
//该类必须实现java.io.Serializable
public class Employ implements Serializable {
public String name;
public int age;
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class test {
public static void main(String[] args) {
//将e转化为字节序列存储于/tmp/1.ser
Employ e = new Employ();
e.name = "zhangyida";
e.age = 15;
try {
FileOutputStream fops = new FileOutputStream("/tmp/1.ser");
ObjectOutputStream obos = new ObjectOutputStream(fops);
obos.writeObject(e);
obos.close();
System.out.println("Serialized data is saved in /tmp/1.ser");
}catch (IOException i){
i.printStackTrace();
}
}
}
import java.io.ObjectInputStream;
public class desEmploy {
public static void main(String[] args) {
Employ e = new Employ();
try {
FileInputStream fis = new FileInputStream("/tmp/1.ser");
ObjectInputStream obis = new ObjectInputStream(fis);
e = (Employ) obis.readObject();
}catch (IOException i){
i.printStackTrace();
return;
} catch (ClassNotFoundException ex) {
System.out.println("Employ class not found!");
ex.printStackTrace();
return;
}
System.out.println(e.name);
System.out.println(e.age);
}
}
stream:
magic version contents
contents
content
contents content
content
object
blockdata
object
newObject
newClass
newArray
newString
newEnum
newClassDesc
prevObject
nullReference
exception
TC_RESET
newObject:
TC_OBJECT classDesc newHandle classdata[]
newString:
TC_STRING newHandle
newClassDesc
TC_CLASSDESC className serialVersionUID newHandle classDescInfo
*classDescInfo
classDescFlags fields classAnnotation superClassDesc
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.IOException;
public class Employ implements Serializable {
public String name;
//public int age;
private void test(String name){
System.out.println(name);
}
private void readObject(ObjectInputStream objin) {
try {
objin.readObject();
Runtime.getRuntime().exec("open /System/Applications/Calculator.app");
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
文章来源:Tide安全团队
黑白之道发布、转载的文章中所涉及的技术、思路和工具仅供以安全为目的的学习交流使用,任何人不得将其用于非法用途及盈利等目的,否则后果自行承担!
如侵权请私聊我们删文
END
多一个点在看多一条小鱼干