View Full Version: File Id 0.1 Alpha

abelhadigital > File ID > File Id 0.1 Alpha



Title: File Id 0.1 Alpha


rloureiro - February 4, 2008 04:31 PM (GMT)
File ID is a file type detection utility. The detection is made by analyzing the content of the file, rather than checking the file extension. The detection is done by a script and this allows 1) to update the detection definitions without having to update the whole application and 2) the user to add new detections or improve existing ones. File ID allows also to retrieve and display other information from the file.

Here are some screenshots to better illustrate the capabilities of File ID:

user posted image
File ID displaying information from a Windows executable.

user posted image
File ID displaying information from a Linux executable.

user posted image
File ID displaying file extensions usually associated to QuickTime movies. Note that although the file extension is .jpg, it has successfully determined the file as a QT movie.

user posted image
File ID displaying the MIME type for a .dmg file (Mac OS X disk image).

Download:
fileid_0.1_alpha.zip

Usage:
Double-click fileid.exe, press the Open button and select a file or just drag'n'drop a file over the main window.

How to add support for more file types:
NOTE: Only advanced or expert users should try this. Any mistake may render the script useless.

Inside the zip file, there are several files but the ones that are absolutely essential are:
* fileid.exe - no explanation needed
* magic.pas - this is the script that contains the instructions for file type detection

Unfortunately, the Help is very incomplete and I haven't found PascalScript tutorials on the web, but since it's based on Object Pascal, for those that don't know Pascal, I recommend reading the first 7 chapters of this ebook: Essential Pascal by Marco Cantu. Also, reading the code in magic.pas is highly recommended for everyone.

If you open the magic.pas distributed in the zip file, you'll find 3 functions:
function DetectMpegAudioFile(const StartOffset: Int64): Boolean;
function DetectTextBasedFile(const StartOffset: Int64; const Encoding: Integer): Boolean;
function Identify(Extension: WideString): LongWord;


The last function is the one that is called by File ID when you open/drop a file. The other two were only added for demonstration and to avoid repeating code.

Here's an example of pascalscript code that only detects PDF documents:
CODE
function Identify(Extension: WideString): LongWord;
begin
 result := 0; // This is the value that will be returned to File ID if the function fails to determine the file type
 FileSeekFromBegin(0); // Go to the beginning of the file
 if (FileReadString(0,5) = '%PDF-') then // Read the first 5 bytes and compare with '%PDF-'
 begin
   SetType('PDF document');
   SetDescription('Adobe Portable Document Format');
   AddMime('application/pdf');
   SetExtension('.pdf');
   AddProperty('_ver','Version','',FileReadString(0,3));
   result := 1; // File type succesfully determined
   Exit; // Stop execution of the script
 end;
end;

begin end.


Note that in the end of magic.pas you'll find this line "begin end.". This line must be present or the script engine won't be able to compile magic.pas.

More information will be posted in the future.

Voluntaries NEEDED!
We want to distribute with File ID 1.0 a magic.pas capable of reliably detect any file type. Because there are probably thousands of file types and each of them may take some considerable time to add proper support, we need people willing to contribute with code for magic.pas. If you want to contribute but don't know where to start, leave a message in this forum or send us an email to info (at) abelhadigital (dot) com.




Hosted for free by InvisionFree