file - 使用另一种语言的 magic.mgc

标签 file unix go libmagic

我目前正在进行一个项目,该项目涉及读取 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/

相关文章:

java - 如何使用java中的BufferReader类逐字节读取文件

python - 遍历文件中的行时进行循环?

sql-server - 如何使用 sqlcmd 从 SQL Server 将数据导出为 CSV 格式?

c - 如何在 C 中将目录拼接到包含路径名的 char * 中?

tensorflow - 在项目中使用go模块时如何导入tensorflow go包?

mongodb - 使用golang从MongoDB批量获取记录

c++ - 通过ofstream输出到文件时 boost 序列化 “read access violation”

C修改printf()输出到文件

python - 多处理和垃圾收集

go - 从传递给函数的结构中获取名称