用于编译/反编译二进制数据文件的通用实用程序或库?
我有各种二进制文件格式,我需要将其转储为某种文本格式,编辑然后重新编译(可能是二进制格式的稍微不同的版本)。当然,我可以用 C/C++ 编写一堆实用程序代码来完成这种事情,并且可能利用一个库来处理文本方面的事情(XML 或 JSON 或其他),但这是一种不断出现的任务模式在我的工作中,在我看来,可能应该已经存在某种用于此类工作的通用工具。
显然,需要某种方式来描述二进制文件格式 - 模式或类似的东西 - 这需要支持所有明显的数据类型(字符串、各种大小的整数、布尔值等,浮点数也很好),以及计数字段、长度字段、填充/对齐等,以处理您在数据文件中找到的所有典型内容。支持字节序也很有用,因为二进制文件的字节序可能与我们运行的平台不同。
如果这样的东西还不存在,我会感到非常惊讶,但到目前为止我还没有通过谷歌(你如何简洁地描述这样的实用程序或库?)。我记得见过的最接近这个的东西是苹果在“经典”Mac OS 时代的资源编译器/反编译器实用程序。它们使用类似 C 的语法,在头文件中使用资源模板定义来描述各种二进制资源的格式,并且您可以在这种类似 C 的源语法和二进制资源之间进行编译/反编译。
I have various binary file formats which I need to dump to some kind of text format, edit and then recompile (possibly to a slightly different version of the binary format). Of course I could write a bunch of utility code in C/C++ to do this kind of thing, and maybe leverage a library for the text side of things (XML or JSON or whatever), but this is a task pattern that keeps cropping up in my work and it seems to me that there probably ought to exist already some kind of general purpose tool for this kind of job.
Obviously there would need to be some way of describing the binary file formats - a schema or some such - this would need to support all the obvious data types (strings, ints of various sizes, bools, etc, floats would be nice too), and things like count fields, length fields, padding/alignment, etc, to handle all the typical stuff that you find in a data file. It would also be useful to have endianness support, as the binary file may have a different endianness than the platform we're running on.
I'd be very surprised if something like this doesn't exist already, but I have had no luck so far via Google (how do you even describe such a utility or library succinctly ?). The closest thing to this I ever remember seeing was Apple's resource compiler/decompiler utilities back in the days of "Classic" Mac OS. These used a C-like syntax, with resource template definitions in header files to describe the formats of the various binary resources, and you could compiled/decompile between this C-like source syntax and the binary resources.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BinX,二进制 XML 描述语言,加上相应的库,似乎适合您的目的。
同样感兴趣的可能是第 24 章实用:解析二进制文件 实用 Common Lisp 书,演示了如何编写用于解析(二进制)MP3 文件中的 ID3 标签的库150 行 Lisp 代码。 **
如今,我可能不会使用 Lisp,而是使用更现代的函数式语言,例如 Clojure。请参阅在 Clojure 中读取二进制数据一个例子。
PS
二进制数据库
或二进制数据文件库
对于 Google 来说是很好的关键字。BinX, the Binary XML Description Language, plus the corresponding library, seem to fit your purpose.
Also of interest might be Chapter 24. Practical: Parsing Binary Files of the Practical Common Lisp book, which demonstrates how to write a library for parsing ID3 tags in (binary) MP3 files in 150 lines of Lisp code. *
* nowadays, i probably wouldn't use Lisp, but a more modern functional language like Clojure. see Reading binary data in Clojure for an example.
P.S.
binary data library
orbinary data file library
are good keywords for Google.Mac App Store 中的“SynalyzeIt”可能值得一看......
"SynalyzeIt" in the Mac App Store might be worth a look...