hex - Delphi - Reading a file signature and compare them -
i need of little in delphi. have search in places can't find answer question.
how can read file signature(4 bytes in case) , put value in hex string? signature program have identify $4e4553a1.
i need test if file, example. c:\happy.bin. have signature. avoid people put wrong format files in software. signature first 4 bytes in it.
thank much, english isn't first language, sorry mistakes. love
this easiest. call , pass in filename.
function checksignature(afilename: string): boolean; var signature: uint32; myfile: tfilestream; begin myfile := tfilestream.create(afilename, fmopenread or fmsharedenywrite); try if myfile.read(signature, sizeof(signature)) = sizeof(signature) result := (signature = $a153454e) else result := false; myfile.free; end; end; the signature reversed because of way integer stores it's data (little endian).
to use function call this:
begin if checksignature('c:\happy.bin') showmessage('matched') else showmessage('didn''t match'); end;
Comments
Post a Comment