我目前正在进行一个项目,该项目涉及读取 file
的魔术文件(无绑定(bind))。我想知道如何以另一种语言(如 Go)直接从编译的二进制文件 magic.mgc
中读取文件测试,因为我不确定其内容应该如何被解释。
最佳答案
根据文件主要贡献者 Christos Zoulas 的说法:
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.
这就是人们应该期待的格式!然而,它必须像原始文件一样被解析。
关于file - 使用另一种语言的 magic.mgc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34280565/