'===============
'MarkExeSize.bas
'===============
'Marks QB64 compiled EXE's with its EXE data size.
'Coded by Dav, JAN/2021
'WINDOWS ONLY!
'This helps facilitate using appended data on the EXE.
'It saves the compiled EXE size to the EXE file, so
'the program can read that info and jump to its data.
'It does this by borrowing some space near the top of
'the EXE file. It shortens 'This program cannot be run
'in DOS mode.' to 'This program can't run in DOS mode.' and
'uses those 4 gained spaces to save EXE file size instead.
'=======================================================
'Example...after you mark your EXE file, it can do this:
'=======
'OPEN COMMAND$(0) FOR BINARY AS 1 'Open itself up...
'test$ = INPUT$(200, 1) 'grab a little info
'place = INSTR(1, test$, "This program can't") 'look for words
'IF place = 0 THEN PRINT "No data found.": CLOSE: END
'grab exesize info...
'SEEK 1, place + 35: ExeSize& = CVL(INPUT$(4, 1))
'Go there....
'SEEK 1, ExeSize& + 1 'where appended data begins
'=======================================================
'NOTE: Always mark the EXE before appending data to it.
' If you use EXE compressors, like UPX, mark the EXE
' AFTER using UPX, not before, otherwise the info won't
' be read correctly by your program.
PRINT "MarkExeSize v1.0 - by Dav"
INPUT "EXE to Mark -->", exe$
'find location of place to mark
place
= INSTR(1, test$
, "This program can") PRINT "This file is not markable."
'jump to location
look$
= INPUT$(19, 1) 'grab a little info
CASE IS = "This program cannot" 'mark/overwrite exe file info file with new info
PRINT "Marking file "; exe$
new$
= "This program can't run in DOS mode." + MKL$(LOF(1)) CASE IS = "This program can't " PRINT "EXE already appears to be marked." PRINT "Data start loc:"; datastart&
+ 1 PRINT "Size of data :";
LOF(1) - datastart&
PRINT "EXE is not markable."