Magic

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Magic
Ontology

I'm sure there are all sorts of almanacs with custom notation that talk about magic, but this page exists to talk about (and link to/from elsewhere on the wiki where needed) the convention of (typically) using the first few bytes of a file to notate/detect the reported format, "as is by magic" (actually by table lookups).

Magic is a string of unique hexadecimal pattern(s) to look for, used in file as, "relatively quick-running heuristics to determine file type, it can report misleading information. The command can be fooled, for example, by including a magic number in the content even if the rest of the content does not match what the magic number indicates. The command report cannot be taken as completely trustworthy."[1] This method, however, is beneficial in somewhat quickly ascertaining whether a or an (extension-less) file is human-readable, or machine code, as opposed to using utilities such as cat to show the contents of a binary file to terminal, can ruin it due to the use of control characters.[2]

It is also used as a library containing a database of magic numbers that can be used, for instance binwalk to, "identify, and optionally extract, files and data that have been embedded inside of other files"[3], based on libmagic signatures.

References

  1. wikipedia:File_(command)
  2. Why (and how) did using cat on binary files mess up the terminal? - Unix & Linux Stack Exchange
  3. What does it do? - binwalk - GitHub
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox