Serialization and Deserialization

I am curious really how a class or serialized at the byte level. I borrow the example from tutorialspoint, modified it a bit and here is what I have right at this moment.

Here is my Employee class and here is my main function.

serial_employeeserial_main

Clearly, the main function will write a file to my desktop and you can use your favorite editor to take a look at the seralized, i.e. binary file. There is a tool called hexedit which might come handy. Here is a screenshot of how the binary file looks like in the text editor.

hexedit

As you can tell, the binary file is a bit messy but most of the contents are almost in a human readable format, say for example, we have 4 attributes and all the string fields are so easy to tell. However, the goal of this post is to 100% decode every byte there and understand how Java really serialized a object.

This really has nothing to do with intelligence but to read the protocol of Java serialization. Here is where the protocol is and of course, it is the only source I have to decipher this binary file.

By the time that I am writing this post, I have not fully decipher every character yet, but I will say I am almost 80% there and here is my progress.

# raw value
aced 0005 7372 0019 636f 6d2e 6461 7461
6669 7265 6261 6c6c 2e45 6d70 6c6f 7965
65da 231e 1f8f 8a0e 4402 0003 4900 066e
756d 6265 724c 0007 6164 6472 6573 7374
0012 4c6a 6176 612f 6c61 6e67 2f53 7472
696e 673b 4c00 046e 616d 6571 007e 0001
7870 0001 0932 7400 0864 697a 6869 e590
8d74 0006 6d69 6e67 7a69 
------
# decipher
aced: (stream magic) 
0005: (stream version)
73: (object)
72: (class description) 
0019: 
636f 6d2e 6461 7461 6669 7265 6261 6c6c 2e45 6d70 6c6f 7965 65: com.data.fireball.Employee
da 231e 1f8f 8a0e 4402 0003 
49: (I)
00 06: (6 bytes)
6e 756d 6265 72: number
4c: (L)
0007: (7 bytes) 
6164 6472 6573 73: address
74: (string marker)
0012: (18 bytes) 
4c6a 6176 612f 6c61 6e67 2f53 7472 696e 673b: Ljava/lang/String; 
4c: (L)
00 04: (4 bytes)
6e 616d 65: name
71 007e 0001 7870 
0001 0932: 67890
74: (string marker)
00 08: (8 bytes)
64 697a 6869: dizhi 
e590 8d: 名
74: (string marker)
0006: (6 bytes) 
6d69 6e67 7a69: mingzi

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s