Skip to content
Johannes vom Dorp edited this page Nov 14, 2019 · 2 revisions

Some initial notes on file magic and how to write it:

Writing Mime-Type Definitions

It might be necessary to write your own mime-type definition. These should be added to src/mime/ (This is not part of the plug-in at the moment ❗). Files in src/mime/ are compiled during the bootstrap procedure. You can use the following command to compile a magic file manually for testing: file -C -m custommime Afterwards you can check your new definition with: file -m custommime.mgc --mime-type FILE_PATH

A simple mime/file definition can look like this:

# Some comment describing your definition
0    string   \x00\x01\x02\x03   some text chown when file is used without --mime-type
!:mime MIME/TYPE

This signature matches all files with hex string "\x00\x01\x02\x03" at offset "0". Have a look at man file to learn about creating more complex signatures.

Your newly created mime-types should hold the following naming conditions:

Category MIME schema
Firmware Container firmware/NAME
File System filesystem/NAME
Compression Streams compression/NAME

👍 Hint: In many cases a file signature is already present in the official file repository, but no mime Type is defined. You could copy the signature definition and add a mime definition in this case.

See our case study for more help on writing your signature.

Clone this wiki locally