Wednesday, January 30, 2008

Convert Shockwave SWF to EXE

Example:
 
Swf2Exe('C:\somefile.swf', 'C:\somefile.exe', 'C:\Program Files\MacromediaFlash MX\Players\SAFlashPlayer.exe');



function Swf2Exe(SourceSWF, exeFile, FlashPlayer : string): string;
var
SourceStream, DestinyStream, LinkStream : TFileStream;
flag : Cardinal;
SwfFileSize : integer;
begin
result := 'Error';
DestinyStream := TFileStream.Create(exeFile, fmCreate);
try
LinkStream := TFileStream.Create(FlashPlayer, fmOpenRead or fmShareExclusive);
try
DestinyStream.CopyFrom(LinkStream, 0);
finally
LinkStream.Free;
end;

SourceStream := TFileStream.Create(SourceSWF, fmOpenRead or fmShareExclusive);
try
DestinyStream.CopyFrom(SourceStream, 0);
flag := $FA123456;
DestinyStream.WriteBuffer(flag, sizeof(integer));
SwfFileSize := SourceStream.Size;
DestinyStream.WriteBuffer(SwfFileSize, sizeof(integer));
result := '';
finally
SourceStream.Free;
end;
finally
DestinyStream.Free;
end;
end;

2 comments:

Sun said...

Thx for sharing the code, which works fine. But this is a little difficult for beginners. I currently use Flash2X EXE Packager. It's a nice program to convert SWF files into EXE files.

KIRAN said...

I completely agree with you. But then if you are familiar with Delphi and know how to code in Delphi, then this is not a tough game to understand. By the way, Flash2X Exe Packager is not a freeware, they charge around $20.