Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to determine the type of a file without knowing the file's extension?

I have a table with a binary column which stores files of a number of different possible filetypes (PDF, BMP, JPEG, WAV, MP3, DOC, MPEG, AVI etc.), but no columns that store either the name or the type of the original file. Is there any easy way for me to process these rows and determine the type of each file stored in the binary column? Preferably it would be a utility that only reads the file headers, so that I don't have to fully extract each file to determine its type.

Clarification: I know that the approach here involves reading just the beginning of each file. I'm looking for a good resource (aka links) that can do this for me without too much fuss. Thanks.

Also, just C#/.NET on Windows, please. I'm not using Linux and can't use Cygwin (doesn't work on Windows CE, among other reasons).

like image 264
MusiGenesis Avatar asked Nov 25 '08 21:11

MusiGenesis


2 Answers

you can use these tools to find the file format.

File Analyser http://www.softpedia.com/get/Programming/Other-Programming-Files/File-Analyzer.shtml

What Format http://www.jozy.nl/whatfmt.html

PE file format analyser http://peid.has.it/

This website may be helpful for you. http://mark0.net/onlinetrid.aspx

Note: i have included the download links to make sure that you are getting the right tool name and information.

please verify the source before you download them.

i have used a tool in the past i think it is File Analyser, which will tell you the closest match.

happy tooling.

like image 183
sundar venugopal Avatar answered Sep 28 '22 11:09

sundar venugopal


This is not a complete answer, but a place to start would be a "magic numbers" library. This examines the first few bytes of a file to determine a "magic number", which is compared against a known list of them. This is (at least part) of how the file command on Linux systems works.

like image 20
Paul Fisher Avatar answered Sep 28 '22 10:09

Paul Fisher