«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

How to detect the types of executable files (part 3 of 3)

Demo project, summary, credits and feedback

Demo program

A demo program that exercises our ExeType function is available for download.

The demo includes the ExeType function, along with a simple application that uses ExeType to analyse files dropped on its main window. The types of dropped files are displayed.

The code was developed using Delphi 4 Professional but should compile with later versions of the compiler.

This demo code is merely a proof of concept and is intended only to illustrate this article. It is not designed for use in its current form in finished applications. The code is provided on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. The source code is copyright Peter D Johnson and may be used in any way. If you agree to all this then please download the code using the following link.


In this article we reviewed the key attributes of various types of executable file then sketched out an algorithm for detecting them. We then developed a Delphi function that analysed files and returned a code describing the file type. A demo program to exercise the function was provided.


Thanks are due to Flurin Honegger for suggesting some of the "reasonableness" checks on the DOS header to verify a valid MS-DOS file.


I hope you enjoyed this article and found it useful. If you have any observations, comments, have found any errors or wish to suggest any improvements please get in touch.