序列化PHP字符串的结构 [英] Structure of a Serialized PHP string

查看:198
本文介绍了序列化PHP字符串的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以将我指向记录了序列化php字符串详细信息的资源.我基本上想知道格式/结构,因此可以在VB.NET中编写一个函数以对其进行序列化/反序列化.

I was wondering if anyone could point me to a resource where the details of a serialized php string is documented. I would basically like to know the format/structure so I can write a function in VB.NET to serialize/deserialize it back.

谢谢!

推荐答案

基本结构如下:

标量类型:

  1. 布尔值序列化为:

  1. Booleans are serialized as:

b:<i>;

其中<i>是一个整数,其值为0(false)或1(true).

where <i> is an integer with a value of either 0 (false) or 1 (true).

整数序列化为:

i:<i>;

其中<i>是整数值.

浮点数被序列化为(d表示双精度):

Floats are serialized as (with d meaning double):

d:<f>;

其中<f>是浮点值.

字符串被序列化为:

s:<i>:"<s>";

其中<i>是表示<s>字符串长度的整数,而<s>是字符串值.

where <i> is an integer representing the string length of <s>, and <s> is the string value.

特殊类型:

  1. null只需序列化为:

N;

化合物类型:

  1. 数组序列化为:

  1. Arrays are serialized as:

a:<i>:{<elements>}

其中,<i>是代表数组中元素数量的整数,而<elements>是零个或多个序列化键值对:

where <i> is an integer representing the number of elements in the array, and <elements> zero or more serialized key value pairs:

<key><value>

其中<key>表示序列化的标量类型,而<value>表示可序列化的任何值.

where <key> represents a serialized scalar type, and <value> any value that is serializable.

对象被序列化为:

O:<i>:"<s>":<i>:{<properties>}

其中第一个<i>是代表<s>字符串长度的整数,而<s>是完全限定的类名(类名前面带有完整的名称空间).第二个<i>是代表对象属性数量的整数. <properties>是零个或多个序列化名称值对:

where the first <i> is an integer representing the string length of <s>, and <s> is the fully qualified class name (class name prepended with full namespace). The second <i> is an integer representing the number of object properties. <properties> are zero or more serialized name value pairs:

<name><value>

其中,<name>是代表属性名称的序列化字符串,而<value>是可序列化的任何值.

where <name> is a serialized string representing the property name, and <value> any value that is serializable.

不过<name>有一个问题:

There's a catch with <name> though:

<name>表示为

s:<i>:"<s>";

其中,<i>是代表<s>字符串长度的整数.但是<s>的值因属性的可见性而异:

where <i> is an integer representing the string length of <s>. But the values of <s> differs per visibility of properties:

a.使用 public 属性,<s>是属性的简单名称.

a. With public properties <s> is the simple name of the property.

b.但是,在具有受保护的属性的情况下,<s>是该属性的简单名称,以\0*\0(星号)开头,并用两个NUL字符(即chr(0))括起来.

b. With protected properties, however, <s> is the simple name of the property, prepended with \0*\0 — an asterix, enclosed in two NUL characters (i.e. chr(0)).

c.在 private 属性中,<s>是该属性的简单名称,以\0<s>\0-<s>开头,并用两个NUL字符括起来,其中<s>是完全限定的类名称.

c. And with private properties, <s> is the simple name of the property, prepended with \0<s>\0<s>, enclosed in two NUL characters, where <s> is the fully qualified class name.


还有一些其他情况,例如R:<i>;,它们表示引用,在这里我没有提到(因为老实说我还没有弄清楚它的确切工作原理),但是这应该给您一个参考.关于PHP的序列化机制的一个不错的主意.


There are a few other cases, such as R:<i>;, that represents references, that I haven't mentioned here (because I honestly haven't figured out the exact workings of it yet), but this should give you a decent idea about PHP's serializing mechanism.

这篇关于序列化PHP字符串的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆