DEMO.DESIGN
Frequently Asked Questions
 
| demo party ex- | infused bytes e-mag | ib/news | | | win koi lat

p (2)
From : Andrew Eigus 2:5100/33 25 May 94 18:27:00 Subj : Template on how to get *Windows* EXE descriptions Hello, This source code u may use for detecting windows exe descriptions. Any comments, etc. post by NetMail to: 2:5100/33 or aeigus@fgate.castle.riga.lv ---cut here--- (* Checking descriptions for Windowz filez *) (* Copyright (c) 1994 by Andrew Eigus *) (* Fidonet: 2:5100/33 E-mail: aeigus@fgate.castle.riga.lv *) {$I-} const { GetModuleDescription return values } gmdOk = 0; { success } gmdFileNotFound = 1; { module with such name/pathname could not be found } gmdLowMemory = 2; { not enough memory for dynamic memory operations } gmdReadError = 3; { file read error } gmdNotEXEFile = 4; { module isn't an EXE format file } gmdNotWinModule = 5; { not a Windows module } Function GetModuleDescription(const FileName : string; var Description : string) : byte; { FileName: a name of module that should be checked for description Description: a string-type description will be stored there if found Returns one of the _gmd_ return values (see consts) } const HdrSize = 4096; { the maximum size of the Windows exe header :))) } var f : file; Header : pointer; I : word; Begin Assign(f, FileName); Reset(f, 1); if IOResult = 0 then begin if MaxAvail >= HdrSize then begin GetMem(Header, HdrSize); if FileSize(f) < HdrSize then BlockRead(f, Header^, FileSize(f)) else BlockRead(f, Header^, HdrSize); if IOResult = 0 then begin if Word(Header^) = Swap($4D5A) then { 'MZ' DOS exe signature found } begin if Word(Ptr(Seg(Header^), $18)^) = $40 then begin I := Word(Ptr(Seg(Header^), $3C)^); { got header offset index } if Word(Ptr(Seg(Header^), I)^) = Swap($4E45) then { 'NE' Windows EXE signature found } begin I := Word(Ptr(Seg(Header^), I + 44)^); { got description offset index to I } Move(Ptr(Seg(Header^), I)^, Description, Succ(Byte(Ptr(Seg(Header^), I)^))); GetModuleDescription := gmdOk end else GetModuleDescription := gmdNotWinModule end else GetModuleDescription := gmdNotWinModule end else GetModuleDescription := gmdNotExeFile; end else GetModuleDescription := gmdReadError; FreeMem(Header, HdrSize); Close(f) end else GetModuleDescription := gmdLowMemory end else GetModuleDescription := gmdFileNotFound End; { GetModuleDescription } {--- now test it --- } var FileName, Description : string; Begin if ParamCount > 0 then FileName := ParamStr(1) else begin Write(#10'Enter Windows file name: '); ReadLn(FileName); if FileName = '' then Halt(1) end; Write('GMD '); case GetModuleDescription(FileName, Description) of gmdFileNotFound: WriteLn('E01: File could not be found'); gmdLowMemory: WriteLn('E02: Not enough memory for allocation'); gmdReadError: WriteLn('E03: Could not read file'); gmdNotEXEFile: WriteLn('E04: Not EXE-type file'); gmdNotWinModule: WriteLn('E05: Not a Windows program'); else WriteLn('Description: ', Description) end End. {---cut here---} C'Ya, Mr. Byte

1 p(/) |p p (1)

FAQ - .

design/collection/some content by Frog,
DEMO DESIGN FAQ (C) Realm Of Illusion 1994-2000,
: "DEMO.DESIGN FAQ, http://www.enlight.ru/demo/faq".