Why do file formats have magic numbers?

For example, Portable Executable has several, including the famous "MZ" at the beginning, as well as "PE \ 0 \ 0" at the beginning of the PE header. The Rar file format is "Rar!" the title at the beginning, and some others have similar "magic values" in the file.

What purpose do such magical meanings fulfill?

+3
source share
5 answers

Because users change the file extension or other programs steal the file extension, it allows the application to cancel processing the file in an unknown format, rather than try its best, and then fail at all.

+7
source

unix . , "" - , . . Microsoft , . , "" , Microsoft "" , , , .

+6

.

+1

" ", " , "!

:

  • , , ,
  • UNIX , (she-bang)
  • , , file, ,
  • , , , .
  • , , .
+1

-, , ( ) , . , ( , ), , , , ( - ).

, .

, . , , nn-nn-nn. , , , (, 12-31-99, , , , , -dd-yy), 12 , . , , -, "MM-DD-YY". .

+1

Source: https://habr.com/ru/post/1767576/


All Articles