//-------------------------------------------------------------
/* Exe format to SWF all kinds of conversion programs
Support FLASH6 Format
The source code is easy to read!
A letter live_on@sohu.com a problem
This function is part of my live Flash player
*/
#include <vcl.h>
#pragma hdrstop
#include "exef.h"
//-------------------------------------------------------------
#pragma package (smart_init)
Ansistring exe2swf (ansistring filename)//function name
{
int ifilehandle;
unsigned long ifilelength;
unsigned long ibytesread;
Ansistring Dfilename;
unsigned char *pszbuffer;
unsigned char *buffer;
Ifilehandle = FileOpen (Filename.c_str (), fmopenread);//Open File
Ifilelength = FileSeek (ifilehandle,0,2);//Determine length
FileSeek (ifilehandle,0,0);
Pszbuffer = new Char[ifilelength+1]; Read into source files
if (pszbuffer==null)
{
return (NULL);
}
Ibytesread = Fileread (Ifilehandle, Pszbuffer, ifilelength);
FileClose (ifilehandle);/close
Dfilename=
Dfilename=filename.uppercase (). SubString (1,filename.length ()-4) + ". SWF ";//Generate Target file name
if (FileExists (dfilename))//Determine whether there is
return (NULL);
printf ("%d \ n", ibytesread);
int i=0;
int ii=0;
for (i=0 i<ifilelength-2;i++)//matching recognition character FWS
{
pszbuffer++;
if ((pszbuffer[i-2]==0) && (pszbuffer[i-1]==0) && (pszbuffer[i]== ' F ') && (pszbuffer[i+1]== ' W ') ) && (pszbuffer[i+2]== ' S '))
{
Ii=i;
}
}
I=ii;
Pszbuffer=pszbuffer+i;
Ifilehandle = Filecreate (Dfilename.c_str ());
if (i!=376831&&i!=286719&&i!=811008)//Is 4. 5. 6 version
{
if (! Application->messageboxa ("File format exception! Force playback?", "Warning", IDOK))
return (NULL);
}
FileWrite (Ifilehandle, pszbuffer,ifilelength-i);
FileClose (Ifilehandle);
delete [] pszbuffer;
return (Dfilename);
}