home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / file39a.zip / magic.man < prev    next >
Text File  |  1993-08-05  |  8KB  |  199 lines

  1.  
  2.  
  3.  
  4. MAGIC(4)                                                 MAGIC(4)
  5.  
  6.  
  7. NNAAMMEE
  8.        magic - file command's magic number file
  9.  
  10. DDEESSCCRRIIPPTTIIOONN
  11.        The  _f_i_l_e(1)  command identifies the type of a file using,
  12.        among other tests, a test for whether the file begins with
  13.        a  certain  _m_a_g_i_c  _n_u_m_b_e_r.   The file //eettcc//mmaaggiicc specifies
  14.        what magic numbers are to be tested for, what  message  to
  15.        print  if  a  particular  magic number is found, and addi-
  16.        tional information to extract from the file.
  17.  
  18.        Each line of the file specifies a test to be performed.  A
  19.        test  compares the data starting at a particular offset in
  20.        the file with a 1-byte, 2-byte, or 4-byte numeric value or
  21.        a  string.   If  the  test succeeds, a message is printed.
  22.        The line consists of the following fields:
  23.  
  24.        offset   A number specifying the offset,  in  bytes,  into
  25.                 the file of the data which is to be tested.
  26.  
  27.        type     The  type of the data to be tested.  The possible
  28.                 values are:
  29.  
  30.                 byte     A one-byte value.
  31.  
  32.                 short    A two-byte value (on  most  systems)  in
  33.                          this machine's native byte order.
  34.  
  35.                 long     A  four-byte  value (on most systems) in
  36.                          this machine's native byte order.
  37.  
  38.                 string   A string of bytes.
  39.  
  40.                 date     A four-byte value interpreted as a  unix
  41.                          date.
  42.  
  43.                 beshort  A  two-byte  value  (on most systems) in
  44.                          big-endian byte order.
  45.  
  46.                 belong   A four-byte value (on most  systems)  in
  47.                          big-endian byte order.
  48.  
  49.                 bedate   A  four-byte  value (on most systems) in
  50.                          big-endian byte order, interpreted as  a
  51.                          unix date.
  52.  
  53.                 leshort  A  two-byte  value  (on most systems) in
  54.                          little-endian byte order.
  55.  
  56.                 lelong   A four-byte value (on most  systems)  in
  57.                          little-endian byte order.
  58.  
  59.                 ledate   A  four-byte  value (on most systems) in
  60.                          little-endian byte order, interpreted as
  61.  
  62.  
  63.  
  64.                           Public Domain                         1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MAGIC(4)                                                 MAGIC(4)
  71.  
  72.  
  73.                          a unix date.
  74.        The  numeric  types  may optionally be followed by && and a
  75.        numeric value, to specify that the value is to  be  AND'ed
  76.        with the numeric value before any comparisons are done.
  77.  
  78.        test     The  value to be compared with the value from the
  79.                 file.  If the type  is  numeric,  this  value  is
  80.                 specified  in  C  form;  if it is a string, it is
  81.                 specified as a C string with  the  usual  escapes
  82.                 permitted (e.g. \n for new-line).
  83.  
  84.                 Numeric  values  may  be  preceded by a character
  85.                 indicating the operation to be performed.  It may
  86.                 be  ==,  to  specify  that the value from the file
  87.                 must equal the specified  value,  <<,  to  specify
  88.                 that  the  value  from the file must be less than
  89.                 the specified value, >>, to specify that the value
  90.                 from  the file must be greater than the specified
  91.                 value, &&, to specify that the value from the file
  92.                 must have set all of the bits that are set in the
  93.                 specified value, or ^^, to specify that the  value
  94.                 from  the  file  must  have clear any of the bits
  95.                 that are set in the specified value.
  96.  
  97.                 Numeric values are specified in C form; e.g.   1133
  98.                 is  decimal,  001133 is octal, and 00xx1133 is hexadeci-
  99.                 mal.  to specify that any value will  match.   If
  100.                 the  character is omitted, it is assumed to be ==.
  101.  
  102.                 For string values, the byte string from the  file
  103.                 must match the specified byte string.  The opera-
  104.                 tors ==, << and >> (but not &&)  can  be  applied  to
  105.                 strings.  The length used for matching is that of
  106.                 the string argument  in  the  magic  file.   This
  107.                 means  that a line can match any string, and then
  108.                 presumably  print  that  string,  by  doing   >>\\00
  109.                 (because  all  strings  are greater than the null
  110.                 string).
  111.  
  112.        message  The message to be printed if the comparison  suc-
  113.                 ceeds.   If the string contains a _p_r_i_n_t_f(3S) for-
  114.                 mat specification, the value from the file  (with
  115.                 any specified masking performed) is printed using
  116.                 the message as the format string.
  117.  
  118.        Some file formats contain additional information which  is
  119.        to  be  printed  along  with  the file type.  A line which
  120.        begins with the character >> indicates additional tests and
  121.        messages to be printed.  The number of >> on the line indi-
  122.        cates the level of the test; a  line  with  no  >>  at  the
  123.        beginning  is  considered  to be at level 0.  Each line at
  124.        level _n++11 is under the control of the line at level _n most
  125.        closely  preceding it in the magic file.  If the test on a
  126.        line at level _n succeeds, the tests specified in  all  the
  127.  
  128.  
  129.  
  130.                           Public Domain                         2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. MAGIC(4)                                                 MAGIC(4)
  137.  
  138.  
  139.        subsequent  lines at level _n++11 are performed, and the mes-
  140.        sages printed if the tests  succeed.   The  next  line  at
  141.        level _n terminates this.  If the first character following
  142.        the last >> is a (( then the string after the parenthesis is
  143.        interpreted  as  an  indirect offset.  That means that the
  144.        number after the parenthesis is used as a  offset  in  the
  145.        file.  The value at that offset is read, and is used again
  146.        as an offset in the file.  Indirect  offsets  are  of  the
  147.        form:  ((((_x[[..[[bbssll]]]][[++--]][[_y]]))..   The value of _x is used as an
  148.        offset in the file. A byte, short or long is read at  that
  149.        offset depending on the [[bbssll]] type specifier. To that num-
  150.        ber the value of _y is added and the result is used  as  an
  151.        offset  in the file. The default type if one is not speci-
  152.        fied is long.
  153.  
  154. BBUUGGSS
  155.        The formats _l_o_n_g, _b_e_l_o_n_g, _l_e_l_o_n_g, _s_h_o_r_t, _b_e_s_h_o_r_t, _l_e_s_h_o_r_t,
  156.        _d_a_t_e,  _b_e_d_a_t_e,  and  _l_e_d_a_t_e  are system-dependant; perhaps
  157.        they should be specified as a number  of  bytes  (2B,  4B,
  158.        etc), since the files being recognized typically come from
  159.        a system on which the lengths are invariant.
  160.  
  161.        There is (currently) no support for specified-endian  data
  162.        to be used in indirect offsets.
  163.  
  164. SSEEEE AALLSSOO
  165.        _f_i_l_e(1) - the command that reads this file.
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                           Public Domain                         3
  197.  
  198.  
  199.