size : 1848 uploaded_on : Thu Jan 14 00:00:00 1999 modified_on : Wed Dec 8 14:03:32 1999 title : Selfextractors org_filename : sfx.txt author : The African Chief authoremail : laa12@keele.ac.uk description : How to append data to an executable and find it's position from within the executable keywords : tested : not tested yet submitted_by : The CKB Crew submitted_by_email : ckb@netalive.org uploaded_by : nobody modified_by : nobody owner : nobody lang : plain file-type : text/plain category : delphi-filehandling __END_OF_HEADER__ > Does anyone know how you can calcualate the real size of an EXE file so you > know where the position in the EXE file is where there's an external data > file attatched. > > e.g. a file create by > COPY /B TEST.EXE + TEST.DTA PROG.EXE > > I can do it in plain old Dos but i cant get i to work in Delphi. You can't. Windows binaries have all sorts of things in them that it is difficult to pinpoint exactly where the binary ends from the information in the header. PE (Win32) binaries are even worse than NE (Win16) binaries in this respect. My advice is join the data to the EXE via source code, and then to write a little header to the end of the joined file which contains offsets to the beginning and end of the data. e.g., 1. create a record; Var MyRec = Record Signature : String[4]; ExeSize, DataSize: Longint; end; 2. open your EXE file and your data file 3. fill the record; With MyRec do begin Signature := #4#3#3#5; {a unique signature} ExeSize := FileSize(MyExeFile); DataSize := FileSize(MyDataFile); end; 4. create destination file 5. copy EXE file into it (using BlockRead/BlockWrite) 6. then copy data file into it (--ditto--) 7. then write the record to it (using BlockWrite) 8. close all files When you want to read the data, all you need to do is to; 1. open the file 2. Seek(MyFile, FileSize(MyFile)-Sizeof(MyRec)) 3. BlockRead(MyFile, MyRec, Sizeof(MyRec)) 4. do checks - - If Ioresult = 0 - and MyRec.Signature = #4#3#3#5 - and MyRec.ExeSize > 0 - and MyRec.DataSize > 0 then - everything is okay - so - Seek(MyFile, MyRec.ExeSize) - read your data, until MyRec.DataSize, etc, etc. All this may look tedious and involved - but believe me, it is *far* less tedious than trying to walk through the PE header.