简体   繁体   English

二进制反序列化-如何查找,它是什么类型的序列化?

[英]Binary de-serialization - how to find, what type of serialization is it?

I have a .dat file generated by a program. 我有一个程序生成的.dat文件。 The program owner is not against parsing and editing this file, but he will not give anyone answers. 程序所有者不反对解析和编辑此文件,但他不会给任何人答案。

The file mostly consists of variables that are defined in this way: 该文件主要由以这种方式定义的变量组成:

In most cases: 在大多数情况下:

(4 bytes - length of the var name)(var name)(4 bytes of some internal var type)(4 bytes - possibly are elements count)(X bytes of var value)

Rarely: 很少:

(4 bytes - length of the var name)(var name)(1 zero byte)(4 bytes of some internal var type)

So, for example: 因此,例如:

([4 0 0 0][name])[11 0 0 0][1 0 0 0]([9 0 0 0][Alexander])

and

([8 0 0 0][names])[6 0 0 0](length [3 0 0 0])([4 0 0 0][John])([4 0 0 0][Anne])([7 0 0 0][SomeGuy])

I tried to look at boost binary serialization but it doesn't add variable names in the file and I think uses 8 bytes, not 4. 我试图查看boost二进制序列化,但是它没有在文件中添加变量名,我认为使用8字节而不是4字节。

There is no generic way to determine "what type of serialization" it is. 没有通用的方法可以确定“什么类型的序列化”。 The author of the format has made design decisions and arrived at a final format. 该格式的作者已做出设计决定,并最终确定了格式。 It could be literally anything. 它实际上可以是任何东西。 You can make educated guesses ("reverse engineering") but the only way to know for sure is to obtain a specification from the author. 您可以进行有根据的猜测(“逆向工程”),但是唯一可以确定的方法是从作者那里获得规范。 Although you claim that he doesn't mind people manipulating files stored in this format, his refusal to provide said specification makes me wonder whether this is really true and, ultimately, means you may have to stick with guesswork. 尽管您声称他不介意人们操纵以这种格式存储的文件,但是他拒绝提供上述说明使我怀疑这是否真的成立,并且最终意味着您可能必须坚持猜测。

To add the the answer of BoundaryImposition there is no deserialization framework (that I know of) that can deal with "any" format. 要添加BoundaryImposition的答案,没有一个反序列化框架(我知道)可以处理“任何”格式。 The format must be known and implemented by the library. 该格式必须由库知道并实现。 So you need to do implement it yourself. 因此,您需要自己实施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM