Grab the source of the file command. Most if not all open sources unices use this one. The file
command comes with the magic
database, named after the magic numbers that it describes. (This database is also installed on your live system, but in a compiled form.) Look for the file that contains the description text that you see:
grep 'Berkeley DB' magic/Magdir/*
The magic
man page describes the format of the file. The trigger lines for “Berkeley DB” are
0 long 0x00061561 Berkeley DB
0 belong 0x00061561 Berkeley DB
12 long 0x00061561 Berkeley DB
12 belong 0x00061561 Berkeley DB
12 lelong 0x00061561 Berkeley DB
12 long 0x00053162 Berkeley DB
12 belong 0x00053162 Berkeley DB
12 lelong 0x00053162 Berkeley DB
12 long 0x00042253 Berkeley DB
12 belong 0x00042253 Berkeley DB
12 lelong 0x00042253 Berkeley DB
12 long 0x00040988 Berkeley DB
12 belong 0x00040988 Berkeley DB
12 lelong 0x00040988 Berkeley DB
The first column specifies the offset at which a certain byte sequence is to be found. The third column contains the byte sequence. The second column describes the type of byte sequence: long
means 4 bytes in the platform's endianness; lelong
and belong
mean 4 bytes in little-endian and big-endian order respectively.
Rather than replicate the rules, you may want to call the file
utility; it's specified by POSIX, but the formats that it recognizes and the descriptions that it outputs aren't. Alternatively, you can link to libmagic
and call the magic_file
or magic_buffer
function.
file
isn't wrong in this circumstance.