用于编译/反编译二进制数据文件的通用实用程序或库?

发布于 2024-08-19 07:15:43 字数 518 浏览 5 评论 0原文

我有各种二进制文件格式,我需要将其转储为某种文本格式,编辑然后重新编译(可能是二进制格式的稍微不同的版本)。当然,我可以用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回心转意 2024-08-26 07:15:44

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 or binary data file library are good keywords for Google.

谁的年少不轻狂 2024-08-26 07:15:44

Mac App Store 中的“SynalyzeIt”可能值得一看......

"SynalyzeIt" in the Mac App Store might be worth a look...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文