This is a code library + example .exe that will detect a file type based on the contents of the file by using "magic bytes".
Magic bytes reference:
http://en.wikipedia.org/wiki/File_format#Magic_number
CODE LIBRARY
The code library is intended to be used in other applications (such as network sniffers to detect file transfers on the wire). It is flexible enough to add new signatures post-compile via adding them to the Resources\SimpleDefinitions.txt.
The code library is in the StreamInspector.dll
EXAMPLE EXE
To see the library in action I created a very simple (5 minute) application that lets you select a file and attempts to identify what type of file it is based on the contents.
The example exe is the FileInspector.exe
LINUX/UNIX
Not sure why you're even reading this, just use the "File" command
http://linux.about.com/library/cmd/blcmdl1_file.htm
NOTE
Stream Inspector will include the same definitions the unix File command uses in a future version. I've been running into issues with some undocumented madness. If you happen to see the author of this horrific app please punch him in the face for being a d-bag.
.NET 4