INCLUDING FILES IN EXEs, by Ollie Cook oliver.cook@bigfoot.com

This is the first programming article that I've ever written so I hope that I make myself clear enough to be understood. This article is going to take the form of a tutorial which will allow you to get this technique working, and will give you scope to adapt and update the source included. We're going to make a program which will play a WAV file, using only one executable.

Let's get started. Get 12-exe.bas loaded up. It includes a lot of code written by Mike Huff, and is simply to play the WAV were going to include, at a decent quality.

Now. If we're going to append the WAV onto the end of the EXE, once compiled, we are going to have to know where the EXE ends and the WAV begins. Luckily for us, all WAV files begin with the same string: "RIFF". So, what we need to do is to make the EXE scan itself until it finds that string. So to do that, replace offset& = 1 with this:

stringmatch$ = CHR$(82) + CHR$(73) + CHR$(70) + CHR$(70)
OPEN Filename$ FOR BINARY AS #1
FOR loop1& = 1 TO LOF(1) - 4
GET #1, loop1&, RIFFsearch(1)
IF RIFFsearch(1) = stringmatch$ THEN offset& = loop1&: EXIT FOR
NEXT
CLOSE #1
IF offset& = 0 THEN CLS : PRINT "No WAV file detected": STOP

 

That will scan the file into a buffer, four bytes at a time, and check if what's in the buffer matches the header we want. We use stringmatch$ = CHR$(82) + CHR$(73) + CHR$(70) + CHR$(70) instead of stringmatch$ = "RIFF" because if we did that the routine would pick up the wrong 'RIFF' in the file.

Now that the program knows where to find the WAV it's our job just to compile the program and add the WAV onto the end. (To make the sound play correctly replace 11000 in Freq& = 11000 with the actual frequency of the sound you want to attach, in Hertz).

OK, now compile the code to 'exetute.exe', as that's what we referenced to in the source. Now from a DOS prompt type the following:

copy /b exetute.exe + wavfile.wav

That will add on the WAV file to the EXE. The EXE knows where the WAV starts and when run will play it, thanks to Mike Huff, and a little devious thinking.

Please pass on any comments you may have on this article to me at oliver.cook@bigfoot.com - It's my first article, I hope you liked it.




This article originally appeared in The BASIX Fanzine Issue 12 from October 1998.