使用另一种语言的magic.mgc文件。

huangapple go评论98阅读模式
英文:

Use magic.mgc from another language

问题

我目前正在进行一个项目,其中涉及读取file的魔术文件(无需绑定)。我想知道如何在另一种语言(比如Go)中直接从编译后的二进制文件magic.mgc中读取文件测试,因为我不确定应该如何解释其内容。

英文:

I'm currently working on a project which involves reading file's magic files (without bindings). I'd like to know how it would be possible to read the file tests from the compiled binary magic.mgc directly, in another language (like Go), as I'm unsure of how its contents should be interpreted.

答案1

得分: 2

根据file的主要贡献者Christos Zoulas所说:

如果你想直接使用它们,你需要理解二进制格式(它会随时间变化)并将其加载到你自己的数据结构中。[...] 解析文件的代码位于apprentice.c中。查看check_buffer()以了解读取器,以及apprentice_compile()以了解写入器。文件中有一个4字节的魔数,后面是一个4字节的版本号,然后是MAGIG_SET(2)个4字节的计数,每个集合(ascii、binary)都有一个计数,然后是一个以本机字节格式表示的'struct magic'条目数组。

所以这就是你应该期望的格式!然而,它必须像原始文件一样被解析。

英文:

According to Christos Zoulas, main contributor of file:

> If you want to use them directly you
need to understand the binary format (which changes over time) and load
it in your own data structures. [...] The code that parses the file is in apprentice.c. See check_buffer()
for the reader and apprentice_compile() for the writer. There is
a 4 byte magic number, followed by a 4 byte version number followed
by MAGIG_SET (2) number of 4 byte counts one for each set (ascii,
binary) followed by an array of 'struct magic' entries, in native
byte format.

So that's the format one should expect! Nevertheless, it has to be parsed just like the raw files.

huangapple
  • 本文由 发表于 2015年12月15日 11:19:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/34280565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定