genmagic - generate "magic" numbers to identify file type
genmagic [-x character_class] [-i character_class] [-c]
[-C] [-d] [-s string] count
genmagic is used to generate count random bytes, to be used as a magic value in a file, to identify the file type. (See the man page for the command file under Unix, and at least under Solaris, the description of the /etc/magic file, i.e. man -s 4 magic.)
The generated bytes are output as a blank separated sequence of two digit hexadecimal numbers, e.g.: "DE AD BE EF".
Specific characters or character classes may be excluded by means of the various options. By default, all alphanumeric characters in US ASCII are excluded, along with the characters 00, FF and the representation for a newline and a space in the local character encoding (almost certainly 0A and 20). (The goal is, of course, to provide a unique identification for a file type, and the probability of a file starting with these characters by chance is relatively high.)
Before starting generation, genmagic builds a set of bytes to be excluded. This list is initialized with the four characters 0x00, '\n', ' ' and 0xFF. Characters are then added or removed from the set by means of the options -x, -i and -c, which are processed in the order they appear on the command line. For the options -x and -i, the character class parameter can be a single character, an escape sequence (all of the usual C/C++ escape sequences are recognized) or a character class delimited by [...], as in Unix regular expressions. (genmagic always uses the "C" locale when evaluating such specifications as "[[:alpha:]]". Also, range specifiers such as "[a-z]" must be fully contained within one of the categories upper, lower or digit.) If no options are given, genmagic then adds a "-x [a-zA-Z0-9]". For example, to exclude only the lower case consonants, one might specify: "-c -x [a-z] -i [aeiou]"; the first option removes the initial four entries, the second excludes all lower case letters, and the third "includes" (undoes the exclusion) the five lower case vowels.
The following options are supported:
- -x character_class
- Specifies characters to be excluded; genmagic will never generate a value corresponding to one of these characters (unless they are later included by means of a -i).
- -i character_class
- Specifies characters which should not be excluded; undoes the effect (or some of the effects) of a previous -x.
- -c
- Clear the exclusion set. Normally used as the first option, if it is not wished to exclude the four characters initially in the set.
- -d
- Don't generate any duplicate values.
- -C
- Output numbers in C/C++ syntax, i.e. as "0xab", rather than simply "AB". If this option is given, the output can be directly cut and pasted into a C or a C++ program.
- -s separator
- Specify the separator string (default ", " if the -C option has been given, " " otherwise).
The following operands are supported:
- count
- The number of values to be output. Must be an integer greater than 0.
0 no error. 3 Hardware error on standard out.