找不到我的$ HOME / .magic幻数

时间:2018-01-03 21:35:16

标签: linux

我正在使用Linux PC上的软件系统,在那里会输入许多文件'使用手册页中描述的幻数:文件(1)和魔法(5)。系统将有自己的幻数,可能存储在/ usr / share / misc / magic中,但这不是问题。在这个时候,我只是想让原型工作,然后我希望从那里开始。

我的问题是,我认为我正在按照联机帮助页的说明进行操作,但是当我运行时:

file hello

我没有得到我期望的结果。输出是标准的ELF消息,但我希望能够用我自己的消息覆盖默认消息。

到目前为止我做了什么:

  1. 使用下面描述的单行创建$HOME/.magic

  2. 创建了hello.c:

    #include <stdio.h>
    
    main() {
             printf("Hello, World\n");
    }
    
  3. 编译:

    cc -o hello hello.c
    
  4. 十六进制格式的八进制转储:

    od -h hello | head -1
    

    给出输出:

    0000000 457f 464c 0102 0001 0000 0000 0000 0000
    

    并注意文件的第一个字节是十六进制值&#39; 457f&#39;。

  5. 阅读manpage magic(5),我为.magic文件创建了一行:

    0     byte       0x457f        "executable: This file is an ELF file."
    
  6. 我对这些领域的理解是:

    0 - Zero offset from the beginning of the file
    byte - The magic number is being handdled at byte(s)
    0x457f - This is the expected value of the first byte of the file, i.e. the byte with 0 offset from the start of the file.
    executable: This file is an ELF file. - The message that is printed when the file command finds a file with the 0x457f magic number
    

    完成这些任务后,我运行我的文件命令:

    file hello
    

    如上所述,此命令为我提供了ELF文件的标准输出,而不是我的修改版本。

    根据文件(1)联机帮助页,$ HOME / .magic文件优先于/ usr / share / misc / magic(或magic.mgc)文件/目录。因此,即使定义了默认幻数,我的.magic文件也应该覆盖。

    此时,我正在尝试试图找出我做错的事情。例如,我的.magic文件中的格式可能不正确。

    我在互联网上找了一些.magic文件,但到目前为止我还没有找到。有趣的是,我已经找到了一些关于如何使用&#39; file&#39;的文档,但是我没有找到使用本地.magic文件的工作示例。

    任何建议或指示都将受到赞赏。

0 个答案:

没有答案