Is Valid IMAGE_DOS_SIGNATURE

Posted by iira on Stack Overflow See other posts from Stack Overflow or by iira
Published on 2010-04-21T04:10:36Z Indexed on 2010/04/21 4:13 UTC
Read the original article Hit count: 309

Filed under:
|

I want to check a file has a valid IMAGE_DOS_SIGNATURE (MZ)

function isMZ(FileName : String) : boolean;
var
 Signature: Word;
 fexe: TFileStream;
begin
result:=false;
try
  fexe := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  fexe.ReadBuffer(Signature, SizeOf(Signature));
  if Signature = $5A4D { 'MZ' } then
  result:=true;
finally
fexe.free;
end;
end;

I know I can use some code in Windows unit to check the IMAGE_DOS_SIGNATURE. The problem is I want the fastest way to check IMAGE_DOS_SIGNATURE (for a big file). I need your some suggestion about my code or maybe a new code?

Thanks

© Stack Overflow or respective owner

Related posts about delphi

Related posts about header-files